Php timed execution problems, obtaining parameters after sleep

Source: Internet
Author: User
Scheduled execution is required in the project, but the scheduled time is a variable parameter. Instead of starting to use crontab for implementation, the time parameter cannot be customized, you also need to get a passed ID to run the sleep program and run into a problem using the sleep function in php, in s... scheduled execution is required in the project, but the scheduled time is a variable parameter, not a fixed

We started to consider using crontab for implementation, but the time parameter cannot be customized. We also need to get a passed ID to execute the program after sleep.

When using the sleep function in php, a problem occurs. parameters obtained by GET or POST before sleep cannot be obtained after sleep.

Ignore_user_abort (); // The PHP script can be executed even if the Client is disconnected (such as the browser is disabled. set_time_limit (0); // the execution time is unlimited. The default php Execution time is 30 seconds, so that the program can be executed without limit $ interval = $ _ GET ['interval']; // receive the $ _ GET parameter $ id = $ _ GET ['id']; // The id passed when the request is triggered, use flush (); sleep ($ interval); // wait for execution at the set time * // *** after sleep, use the above $ id, to execute other programs. After the test, the $ id cannot be obtained. Blank **/

Do you know anything about it? Or provide other ideas. Thank you!

Reply content:

Scheduled execution is required in the project, but the scheduled time is a variable parameter, not a fixed

We started to consider using crontab for implementation, but the time parameter cannot be customized. We also need to get a passed ID to execute the program after sleep.

When using the sleep function in php, a problem occurs. parameters obtained by GET or POST before sleep cannot be obtained after sleep.

Ignore_user_abort (); // The PHP script can be executed even if the Client is disconnected (such as the browser is disabled. set_time_limit (0); // the execution time is unlimited. The default php Execution time is 30 seconds, so that the program can be executed without limit $ interval = $ _ GET ['interval']; // receive the $ _ GET parameter $ id = $ _ GET ['id']; // The id passed when the request is triggered, use flush (); sleep ($ interval); // wait for execution at the set time * // *** after sleep, use the above $ id, to execute other programs. After the test, the $ id cannot be obtained. Blank **/

Do you know anything about it? Or provide other ideas. Thank you!

Comment out flush

Test executable

Ignore_user_abort (); // The PHP script can be executed even if the Client is disconnected (such as the browser is disabled. set_time_limit (0); // the execution time is unlimited. The default php Execution time is 30 seconds, the program can be executed without limit // params $ interval =$ _ GET ['interval']; // receive the $ _ GET parameter $ id = $ _ GET ['id']; // The id passed when the request is triggered, use flush (); sleep ($ interval); echo $ id;

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.