After I used Pclose (Popen ()) in PHP, I waited for the script running Popen to run to finish before proceeding down.
//test.phppclose(popen('php '.__DIR__.'/index.php','r'));$fp = fopen('product.txt', 'cb');if(flock($fp, LOCK_EX | LOCK_NB)){ echo "ok
";}else{ echo "no
";}fclose($fp);
//index.phpsleep(10);set_time_limit(0);$fp = fopen('product.txt', 'cb');flock($fp, LOCK_EX | LOCK_NB);for($i = 10 ; $i ;$i--){ fwrite($fp,$i."\n"); sleep(6);}fclose($fp);
The 2nd line of code in the test.php waits until the index.php execution is finished before it starts to run, excuse me.
Reply content:
After I used Pclose (Popen ()) in PHP, I waited for the script running Popen to run to finish before proceeding down.
//test.phppclose(popen('php '.__DIR__.'/index.php','r'));$fp = fopen('product.txt', 'cb');if(flock($fp, LOCK_EX | LOCK_NB)){ echo "ok
";}else{ echo "no
";}fclose($fp);
//index.phpsleep(10);set_time_limit(0);$fp = fopen('product.txt', 'cb');flock($fp, LOCK_EX | LOCK_NB);for($i = 10 ; $i ;$i--){ fwrite($fp,$i."\n"); sleep(6);}fclose($fp);
The 2nd line of code in the test.php waits until the index.php execution is finished before it starts to run, excuse me.
pclose(popen('nohup ' . $cmd . ' & 2>&1', 'r'));
pclose(popen('php /path/to/task.php &', 'r'));
Where & is put into the background to execute script task.php.
Also note that if(flock($fp,LOCK_EX))
it will block to get an exclusive lock.