8th February 2008
Most frequent use: convert database from latin1_swedish to utf8_general_ci.
Original script found at: MySQL and UTF-8.
Update: the original script had an error, it would generate queries likes this one (note the bold part):
ALTER TABLE `links` CHANGE `link_rel` `link_rel` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT NULL;
This is clearly wrong syntax (and logic). I fixed this by making comparison to NULL strict (with three equal signs instead of two):
// Does the field default to null, a string, or nothing?
if ($row['Default'] === NULL)
Update 2: based on comment by banesto, I modified the script; now it does not require specifying the from_collation, it’s sufficient to specify to_collation (which will be used for all the fields and tables). The modified code is:
if ($row['Collation'] == ” || $row['Collation'] == $convert_to)
continue;
Update 3: the long-lasting, re-appearing NOT NULL DEFAULT NULL problem is finally fixed.
Update 4: incorporated Russ’s fix to skip numeric fields (in order to leave autoincrement values intact).
Here’s the script itself: (to copy-paste: first click the “Plain text” header)
Read the rest of this entry »
Posted in Links, Notepad, PHP, Programming, Web | 60 Comments »
16th October 2007
Today, setting up a relatively serious (in CPU resources needed) web-system, I ran into a weird problem of python scripts ending prematurely. After some investigation, it looked like any process which uses up more than 20 seconds of CPU time, is automatically killed. To verify this, I wrote an infinite loop in C,
int main () {
unsigned int i;
for (i = 0; i < 2 ; i++ ) {
i = 0;
}
return 0;
}
[/c]
compiled it and executed several times on the GoDaddy shared hosting server. I did observe the program running for the maximum of 20 seconds of CPU time, not a second more. Please note, that 20 seconds of CPU time can be much more of “real” time, if the script isn’t using 100% of CPU, which often the case for shared hosting. Thus if you have in your php.ini max_execution_time set to, say, 60 seconds, your php script may actually execute as long as one minute; but I’m pretty sure that if your script has lots of CPU-intensive procedures, then as soon as it uses 20 seconds of CPU time, it will be terminated (however, this statement still needs checking – anyone?).
To verify, I also created a cron job with the same file. It ran for 30 seconds CPU time.
Strangely, this behaviour is not documented anywhere.
This limit may also explain a number of other problems, if you have heavy web-applications: they just might be killed before they are finished, causing errors.
I do understand the reason for this limitation, and am sure similar limitations exist in other shared hosting environments. The only important thing here is that this limit should have been documented and even put upfront somewhere in the hosting plans descriptions.
I also wonder if the limit is the same for all godaddy shared hosting plans, or if it differs. 20 seconds when executed from PHP, and 30 seconds when executed as a cron job were observed on the Deluxe Linux Hosting plan.
Extensions, additions and comments are welcome.
Posted in *nix, Misc, Programming, Web | 22 Comments »