tags:

views:

193

answers:

1

any solution to this ?

#!/usr/bin/php -q 
<?php
set_time_limit(2);
sleep(5);
echo "it didn't work again";
+2  A: 

The max_execution_time limit, which is what set_time_limit sets, counts (at least, on Linux) the time that is spent by the PHP process, while working.

Quoting the manual's page of set_time_limit() :

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.
This is not true on Windows where the measured time is real.

When, you are using sleep(), your PHP script is not working : it's just waiting... So the 5 seconds you are waiting are not being taken into account by the max_execution_time limit.

Pascal MARTIN
thanks for the answer, however i still have the solve the problem, is there anyway that I can do this using another approach ?
Devrim
Well, I'd say should not not `sleep()`, if you don't want the script to remain alive for more time than necessaray ;-) ;;; more seriously, `max_execution_time` is meant as a security precaution against scripts that would take too much resources, and not as any kind of precise timing mecanism.
Pascal MARTIN
there is an exec() running instead of sleep() there. and some exec() stuff hangs indefinitely. i am also searching for killing it from within exec (on linux shell), like exec(kill_after15secs myscript.sh), but i can't seem to find that either...
Devrim
Oh, I understand better, now, why you need this ^^ ;;; sorry, I don't have any realy solution, there :-(
Pascal MARTIN