PHP Popen after waiting for the script to be executed before execution down, how to solve?

Source: Internet
Author: User
Keywords Php
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.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.