I need to run some PHP scripts in the background, this script should still run while i log off my SSH session. I first try php myscript.php & It run in the background, but then when my SSH ends, the job will be also suspended. After some research, finally, i found that i can use nohup command to do this job, it’s very simple nohup php myscripts.php & Remember to add & at the end of the script. If you want to check if it’s actually runnning, use this commmand jobs -lRead More →

I was trying to install TMS Component v6.0 into my Delphi 7 (yes, it’s very old), everything seems working fine. I can see the new components installed, i can drag it to my form. Run it perfectly. Then i saved the form, project , re-open them , an error message showing up: “Error Reading Form” – Class TAdvPage not found. > What happened here? i could see it in my design pallet, i searched google and they suggest that the design package was not installed ? I could design it, so it must be installed. I have been struggling this for many days. It turnedRead More →

Long time ago, when i design the database, i never think of the character set for my database. But recently, i have to work on some non-english language like Chinese and Korean. I found that my database does not store the info correctly. So here is my suggestion: No matter if you decide to support multiple language or not, when you design your database, you should use UTF-8 as the character set. If you are using mysql and your database is not not with UTF8 – you should use this query to convert it to UTF8. ALTER TABLE table_name CONVERT TO CHARACTER SET utf8 COLLATERead More →

Here is the code to utilize Google Translate to translate any text to English for free. / this function translates chinese to english if you want to use this function, please write your own curl_post_content – it’s just a curl request using post method – i have my own curl_post_content which i can’t publish here. the data that google returns doesn’t work well with json_decode function, we have to fix it a little bit, see the str_replace function here / function translate_to_english($text) { $url=”https://translate.google.com/translate_a/single?client=t&sl=auto&tl=en&hl=en&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&dt=at&ie=UTF-8&oe=UTF-8&otf=2&srcrom=0&ssel=0&tsel=0&source=btn&kc=2&tk=523995|731640“; $data=array(); $text=strip_tags($text); $data[“q”]=$text; $response=curl_post_content($url,$data); $response=str_replace(“,,”,”,0,”,$response); $response=str_replace(“,,”,”,0,”,$response); $response=str_replace(“[,”,”[0,”,$response); $obj =json_decode($response,true ); //true converts stdClass to associative array. $result=””; foreach($obj[0] as $v) {Read More →

I have a Chinese text file that’s not encoded in UTF8 , it’s encoded with gb2312 . I have been struggling to insert it into mysql. When i copy the text file & import it to mysql via phpmyadmin, it display chinese character very well, but if i use php to insert it, it display some weird characters. It turned out that i need to re-encode gb2312 to ut8 in php before inserting to database. The reason when it’s working fine via phpmyadmin, it’s because when we copy & paste, the browser already re-encode from gb2312 to utf8. here is the function i use: $text=Read More →

Svnx doesnt have interface to switch the svn repository from one url to another. If you change your url , or move your repository to a new url you can do this. Open the terminal Using “cd” command to go to your repsoitory , e.g. cd /Users/yourname/websites/abc.com (abc.is your svn) then run the command svn switch –relocate old_url new_url if you want to check your old url , you can run the command “svn info”Read More →

When you think your mysql is slow , the first step is to analyze your sql query with “Exlain” command. This is an example explain select * from table1 inner join table2 on table1.field1=table2.field2 and table.field3 =577458498 It will give you some thing like this , look at the “rows” column , if the number of that column is too high, try to reduce it by changing your query , or add index. +——–+——+——————-+———+———+——-+——+———–+ |table | type | possible_keys | key | key_len | ref | rows |Extra | +——–+——+——————-+———+———+——-+——+———–+ |employee| ref | surname,surname_2 | surname | 41 | const | 1 |where used |Read More →

If I’m ever wondering how long my PHP scripts take to execute, I add this code to the start of my pages: Then I add this to the end of my script: Sometimes it’s good to get hard figures on how long your script takes to execute, particularly with complex MySQL queries. If your script is particularly tardy and you want to find out where the blockage occurs, you could also try moving the $Start or $End lines to different parts of the script to measure the execution speed of each section.Read More →