0

We have a node js script that runs a command to execute the following command:

/usr/local/bin/php -q /home/www/441.php {"id":"325241"}

This script does a lot of things, however it does not seem to respect the time limit. The first line of this file is:

set_time_limit(1800);

Yet if we check what processes are running on the server (ps -aux | grep php) we will see a lot of these commands that have been open since last week.

Any ideas on how we can clean this up?

3 Answers 3

2

I found the following comment on the PHP user guide for max_execution_time

Keep in mind that for CLI SAPI max_execution_time is hardcoded to 0. So it seems to be changed by ini_set or set_time_limit but it isn't, actually. The only references I've found to this strange decision are deep in bugtracker (http://bugs.php.net/37306) and in php.ini (comments for 'max_execution_time' directive).

So it would seem that there's a bug in the CLI module that means max_execution_time is effectively ignored.

The commenter mentioned a page in the bug tracker about this at http://bugs.php.net/37306 but the tracker seems to be down.

Sign up to request clarification or add additional context in comments.

Comments

1

set_time_limit only has meaning to the php part of the program. If you had a query on a database that takes 5h to finish, those 5h are not counted by php, so they fall out of scope of the set_time_limit limitation. Having said that, it seems weird that a php process is still running after a week, if it is not calling another program that runs forever (which, in this case, the set_time_limit neither affects that calling).

Also, what does the -q flag? I can't find it on man php nor php --help nor in php's command line options.

2 Comments

-q is quiet-mode. Suppress HTTP header output (CGI only).
Thanks, I think the problem is with another piece of software that the PHP script calls, and that is hanging not the PHP itself which is why set_time_limit won't work.
0

If you start the script in nodejs, why not kill it there too, after 1800s?

var pid = startPHPProcess();

setTimeout(function() {
    killPHPProcess(pid);
}, 1800);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.