mysql server has gone away or connection timeout

If you do a lots of things in one php script this usually takes some time and mysql can gone away 😉 for this when you run new query you can run it with this function which will connect again to mysql if previous connection is closed from timeout


function run_query($sql){
global $link, $db;

if(!mysql_ping($link)){
$link = mysql_connect($db[‘host’], $db[‘user’], $db[‘pass’], true);
mysql_select_db($db[‘db’], $link);
}

return mysql_query($sql, $link);

}

С етикет: , ,
Публикувано в linux, php

php recursive copy

This function copy recursive files and folders in php

function recursive_copy($src,$dst) {
$dir = opendir($src);
@mkdir($dst);
while(false !== ( $file = readdir($dir)) ) {
if (( $file != ‘.’ ) && ( $file != ‘..’ )) {
if ( is_dir($src . ‘/’ . $file) ) {
recurse_copy($src . ‘/’ . $file,$dst . ‘/’ . $file);
}
else {
copy($src . ‘/’ . $file,$dst . ‘/’ . $file);
}
}
}
closedir($dir);
}

Публикувано в linux, php

php recursive delete

This function do recursive delete on files and folders in php

function recursiveDelete($str){
if(is_file($str)){
return @unlink($str);
}
elseif(is_dir($str)){
$scan = glob(rtrim($str,’/’).’/*’);
foreach($scan as $index=>$path){
recursiveDelete($path);
}
return @rmdir($str);
}
}

С етикет: , , ,
Публикувано в linux, php

extra space after textarea differ in different browsers

There is different space after textarea in Chrome, Firefox, Opera and IE

To fix this problem you need to add following to the css style of the textarea element

vertical-align: top

С етикет: , , , , ,
Публикувано в css

debuging high IO wait under linux

To do that you can use block IO debugging capability of Linux kernel.

echo 1 > /proc/sys/vm/block_dump

After this run

dmesg | egrep "READ|WRITE|dirtied" |  awk '{print $1}'|  sort | uniq -c | sort -rn | head
   1583 kjournald(2764):
    545 kjournald(1023):
     48 beam.smp(21021):
     47 sendmail(20992):
     28 crond(20974):

Now disable the block IO debugging

echo 0 > /proc/sys/vm/block_dump
Публикувано в linux