|
Posted by Erwin Moller on 11/04/09 11:32
hakim wrote:
> Hi NG,
Hi Hakim.
I saw this question (in another incarnation) a few times before here.
That probably means you are not very lucky getting answers.
(I have a few wild suggestions for you to test, but if that doesn't help
you, you could submit a bugreport to Zend, with a code example.)
>
> I have my own apache server 2.0.54 running with php 4.3.10 on debian
> sarge.
>
> I got a little logical problem here about http requests.
>
> I have written a small php script which waits for 360 seconds. Every
> second it appends the seconds to a file.
>
> I expected a timeout after 300 seconds, because apache is configured
> like that. But until now it doesn't matter. I can wait for more than 5
> minutes and the script finishes i see the result page.
> On the other hand I expected a timeout after 30 seconds, because
> max-execution-time in php.ini is set to 30.
>
> One apache group user said, that maybe the max-execution-time of
> php.ini maybe only applies to CPU time (non-sleeping).?
this is wat php.net has to say about that:
[source: http://nl2.php.net/info]
**********************************
max_execution_time integer
This sets the maximum time in seconds a script is allowed to run before
it is terminated by the parser. This helps prevent poorly written scripts
from tying up the server. The default setting is 30.
The maximum execution time is not affected by system calls, stream
operations etc. Please see the set_time_limit() function for more details.
You can not change this setting with ini_set() when running in safe
mode. The only workaround is to turn off safe mode or by changing the time
limit in the php.ini.
Your webserver can have other timeouts. E.g. Apache has Timeout
directive, IIS has CGI timeout function, both default to 300 seconds. See
the webserver documentation for meaning of it.
*********************************
and set_time_limit:
***********************************
Description
void set_time_limit ( int seconds )
Set the number of seconds a script is allowed to run. If this is reached,
the script returns a fatal error. The default limit is 30 seconds or, if it
exists, the max_execution_time value defined in the php.ini. If seconds is
set to zero, no time limit is imposed.
When called, set_time_limit() restarts the timeout counter from zero. In
other words, if the timeout is the default 30 seconds, and 25 seconds into
script execution a call such as set_time_limit(20) is made, the script will
run for a total of 45 seconds before timing out.
Warning
set_time_limit() has no effect when PHP is running in safe mode. There is no
workaround other than turning off safe mode or changing the time limit in
the php.ini.
Note: The set_time_limit() function and the configuration directive
max_execution_time only affect the execution time of the script itself. Any
time spent on activity that happens outside the execution of the script
such as system calls using system(), stream operations, database queries,
etc. is not included when determining the maximum time that the script has
been running.
****************************************
The note is maybe of special interest to you because this might be excactly
what the other user (in apachegroup) told you.
sleep() could just not count as time used up, but I don't know this for
sure.
Test:
To test this I would suggest you replace you sleep(1) call by something that
really uses up cpu time.
(eg: Some stupid loop, or try to calculate the first 1000 primenumbers, or
whatever)
What happens now?
>
> Anotherone said, that I am not using the right php.ini. But in
> phpinfo(); it's:
>
> Configuration File (php.ini) Path: /etc/php4/apache2/php.ini
>
> And that's the php.ini i am working with.
Well, that is simple to test.
Just change something in php.ini and check if it affects your php-script.
You can simple get the php,ini settings by using:
ini_get("somedirectivehere");
replace "somedirectivehere" with something you find here for example:
http://nl2.php.net/manual/en/ini.php
>
> How I can prevent scripts of running endless??? Which parts are
> responsible? Does my script stop on your installations after the time
> of max-execution-time?
Of course you can also program your own max_executiontime if this directive
keeps giving you troubles.
Just remember the time when you script starts, and in your for/next or
while-loop, check for time passed.
You can use microtime() for this purpose if you want to be excact.
>
> Here the code:
>
> <?php
>
> // All print functions do not show up on the screen until it is
> finished
> print 'Now we wait<br>';
>
> for($i = 1; $i <= 360; ++$i) {
> sleep(1);
> print "$i<br>";
> $handle = fopen('test.dat', "a");
> fwrite($handle, $i . "\n");
> fclose($handle);
> }
>
Looks fine to me...
> print '<br><br>End...<br>';
>
> ?>
>
> Thanks...
Good luck.
Please repost your results here.
Regards,
Erwin Moller
Navigation:
[Reply to this message]
|