<? print “Starting main program\n”; $childs = array(); for ( $count = 1; $count <= 10; $count++) { $pid = pcntl_fork(); if ( $pid == -1 ) { // Fork failed echo “Fork failed\n”; exit(1); } else if ( $pid ) { # parent #print “pid is $pid, parent $$\n”; array_push($childs, $pid); } […]
Debugging PHP – Parse error: syntax error, unexpected $end If you have are using the short form <? for PHP instead of the long form <?php you might be faced with this parse error when running your script on different systems: Update all references to the long version <?php Ensure that all linked files also […]
The PHP date() function is used to format a time and/or date. The PHP Date() Function The PHP date() function formats a timestamp to a more readable date and time. A timestamp is a sequence of characters, denoting the date and/or time at which a certain event occurred. Syntax date(format,timestamp) Parameter Description format Required. Specifies […]
PHP Array An array stores multiple values in one single variable. What is an Array? A variable is a storage area holding a number or text. The problem is, a variable will hold only one value. An array is a special variable, which can store multiple values in one single variable. If you have a […]
Given a size in KB, try to return a more readable MB, GB or TB answer string function readable_size_for_kb($mykb) { if ( $mykb > 1073741824 ) { return sprintf(“%5.1f TB”,$mykb / 1024 / 1024/1024); } elseif ( $mykb > 1048576 ) { return sprintf(“%5.1f GB”,$mykb / 1024 / 1024); } elseif ( $mykb > 1024 […]
Readable Time – PHP, given a UNIX timestamp, return a readable time # Given a unix timestamp, returns in readable time ie “1 day, 7 hours, 23 minutes, 2 seconds” function readable_time($timestamp, $num_times = 2) { //this returns human readable time when it was uploaded (array in seconds) $times = array(31536000 => ‘year’, 2592000 => […]