Skip to content

Instantly share code, notes, and snippets.

@edmhs
Last active March 20, 2019 10:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edmhs/2a2b8039a8baacd4ffe3267f91418588 to your computer and use it in GitHub Desktop.
Save edmhs/2a2b8039a8baacd4ffe3267f91418588 to your computer and use it in GitHub Desktop.
Very old hack to run multiple php processes. Named "daksa" in translation from Latvian mean "Fork"
<?php
echo date('Y-m-d H:i:s')."\n";
// filename to run
$filename = "check_count.php";
// max processes
$processes = 8;//rand(0,1);
$total = 0;
// get all active server php processes, exclude grep search record
exec("ps auxwww|grep php|grep -v grep", $output);
// print_r($output);
// match required script and count how many are running
foreach($output as $out){
if (strpos($out,$filename) !== false) {
$total++;
}
}
echo $total." processes\n";
# if running less then required, start new processes
if($total<$processes){
run_proces($filename,($processes-$total));
}
# start multiple processes function
function run_proces($filename,$count=1){
$done = 0;
while($done<$count){
exec("php /var/www/html/math/$filename > /dev/null 2>/dev/null &");
echo "Runned another process \n";
$done++;
sleep(2);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment