IIS 7 long timeout on individual PHP script - php

I know there was some trick with the metabase in IIS 6 to do this, but 7 is different.
Basically, I have a long-running PHP script that handles its own timeout in the regular PHP way, that keeps getting killed by the server before it's done. I need the IIS 7 procedure for giving it a long or no timeout on just that one script and no others.

check set_time_limit function.
set_time_limit(0); //will remove execution time limit
http://php.net/manual/en/function.set-time-limit.php

Related

Limit of concurrent PHP scripts

I have some PHP scripts that process data
unfortunately I can only run 6 script simultaneously
it seems that there is some sort of limitation in php or apache that makes the 7th script waits until another script ends
the script only processes data, there isn't any kind of connection with the database or any web request
How can I increase this limit?
#Leo - How are you running these scripts simultaneously? Is it web browser calling it (as you have mentioned apache in question)? -- browser has simultaneously connection limit. OR some other scenario.
place this function top of each page.
set_time_limit(0);
more details you can found on
http://php.net/manual/en/function.set-time-limit.php

How to increase execution time of shell commands? [duplicate]

This question already exists:
Python execution from php
Closed 6 years ago.
I am using exec() to run python script from cakephp, upto 30 seconds it is working fine after that php is aborting but still in background python is running to complete the process.
I am using ajax post method and running python and waiting for response. In this workflow if execution of python is crossing 30 seconds the php is not waiting for the response. I am using nginx server. I tried to modify php.ini file to increase max_execution_time=600. But still the issue remains same.
Use set_time_limit() for example:
<?php
set_time_limit(40);//set script's execution time limit to 40 seconds
in large backstage task, I usually apply set_time_limit(0); which means no time limit is imposed.

How to trace a script running successfully or timeout in PHP

I have a PHP script which running some crawling job, and which probably require 5 minutes above to complete.
My question as below:
If I try to execute the script via browser request, probably will experience a request timeout after 30 seconds, but is it the script still running on server until completion?
If I execute the script via cron job, how do I trace the running status? How do I know if the script still running or already been kill by server?
Is it possible to increase the maximum execution time via PHP code without touching the php.ini file?
Appreciate for the reply.
If I try to execute the script via browser request, probably will
experience a request timeout after 30 seconds, but is it the script
still running on server until completion?
your script also stop processing on server.
If I execute the script via cron job, how do I trace the running
status? How do I know if the script still running or already been kill
by server?
You can track it by putting log in file at beginning of your script and at the end of your script.
Is it possible to increase the maximum execution time via PHP code
without touching the php.ini file?
You can increase the maximum execution time via PHP code by
ini_set('max_execution_time',300);
but it will only work if your HTTP_CONNECTION variable is set to keep-alive on server.

long running php script called via ajax (Don't want to wait for response)

I have a long running script that can run for awhile. (It sends an email every 5 seconds) to many users. This script is triggered via an ajax request
If the response is never received such as the browser is closed, will the script continue to run? (It appears it does, but are there any conditions on when it won't?
Does sleep count towards the max execution time. (It appears this is false also)
1.
The short answer is: it depends.
In fact, it can be configured in PHP and in web server you use. It depends on the mode you use PHP in (module or CGI or whatever).
You can configure it sometimes, though. There is an option in php.ini:
/* If enabled, the request will be allowed to complete even if the user aborts
; the request. Consider enabling it if executing long requests, which may end up
; being interrupted by the user or a browser timing out. PHP's default behavior
; is to disable this feature.
; http://php.net/ignore-user-abort
;ignore_user_abort = On*/
2. Almost always sleep does count. There are conditions when it does not, but in that case not the execution time is measured but execution cpu time. IIS does count CPU usage by app pools, not sure how it applies to PHP scripts.
It is true that PHP does not kill a script that is in sleep right now. That mean that the script will be killed once the sleep is over (easy test: add sleep(15); to your php and set max execution time to 10. You will get an error about time limit but in 15 seconds, not in 10).
In general, you can not rely on freely using sleeps in script. You should not rely on script that is run without a user (browser) within a web server, either. You are apparently solving a problem with wrong methods: you really should consider using cron jobs/separate tasks.
This depends on the server. Some servers could terminate the script when the socket is closed (which will probably happen when the browser is closed), others could let the script execute until the timeout is reached.
Again, would depend on the server. I can really see a implementation looking at the time the script puts load on a CPU, then again - just measuring how long ago the script was started is an equally good approach. It all depends on what the person(s) making the server software was after.
If you want definite answers I would suggest sifting through the documentation for the webserver and php-implementation your script is running on.

PHP with lengthy loop creating erratic server error

I have a PHP script that pulls down a bunch of RSS feeds. To prevent overloading the publishers' servers, I use the PHP Sleep function to slow things down.
The entire script could last for a couple of hours.
If I run this from a Cron job on GoDaddy, it will happily work for 5 - 10 minutes and then return a server error. I checked and the PHP maximum execution time is 30 seconds, so I'm not sure if this is the cause of the problem.
If I run the job on my Mac, my local PHP also has a default maximum execution time of 30 seconds, but this script does work if I run it from the terminal, but I don't understand why.
How do I loop a script that will exceed 30 seconds without running into unreliability problems?
Help appreciated.
Short answer is use set_time_limit(0) to allow for a long-running script. Your terminal (CLI) PHP probably has it set to 0. You could also be running out of memory, especially on PHP 5.2 or older. Log all errors to a file, and inspect it.
You could rewrite your program to be able to work on a subset of the data during one run. The benefit of that approach is you could use it to run 24/7 or to run every five minutes, depending on what the PHP environment supports. You could also run multiple instances at a time, each working on their own data.

Categories