问题
I have a line of code that needs to be executed from an user-defined start time to an user defined end time.
The problem is that a normal loop from start to end doesn't work because PHP gives me an error of "Execution Time Limit Exceeded".
How do I get this done without using CRON jobs? (I need to run my server on a Windows PC)
回答1:
Windows or not it's not excuse. Any platform features tools to let you do scheduled tasks. So does Windows. Here is tutorial about setting up Scheduled Tasks on Windows to achieve same results like you can with cron.
EDIT
I need to do this on a web-browser. It needs to be platform independent.
You can't really. The only trick to do something close to cron w/o cron is to check dates on each request users made to your scripts and if the time is right, fire do some job. But if noone visit your site then you start nothing.
Other option is to setup cron which would do the request to your page (i.e. using wget, lynx, HEAD etc). But it still needs the "driving force" like cron or equivalent
回答2:
Try to change your "Execution Time Limit" in your PHP.ini
回答3:
I solved the problem. Using javascript and the setTimeout() function, I sent a GET request to the necessary php script and the line of code was executed after that delay.
来源:https://stackoverflow.com/questions/13551208/run-a-line-of-php-code-from-user-defined-start-time-to-end-time-without-using-cr