Hi All,

On php.net i read this"The maximum execution time is not affected by system calls", does this also mean that when i run a cronjob from direactadmin max_execution_time does not kick in? or any other time outs?

thanks a lot for answering this!!

Gr josek

Recommended Answers

All 3 Replies

Hi,

it depends on the OS: on Windows the measured time is the real time; on Linux system calls do not affect the execution time. Read the note at this page:

You can test it by yourself:

<?php

    ini_set('max_execution_time', 1);

    while(true)
        echo 'hi ' . date('H:i:s') . PHP_EOL;

And:

<?php

    ini_set('max_execution_time', 1);

    while(true)
    {
        system('sleep 3');
        echo 'hi ' . date('H:i:s') . PHP_EOL;
    }

And then run:

time php script.php

In the first case at the end of the execution you will see something like:

Fatal error: Maximum execution time of 1 second exceeded in script.php on line 6

real    0m1.224s
user    0m0.712s
sys 0m0.224s

In the second case you have to hit CTRL + C, otherwise it will never end. The sleep() function will act as the system call.

Is this answering his question?

i think he means is there a difference between http (browser) requests and cronjobs regarind max_execution_time?

although i do not know the answer i hope to have cleared this thread.

;)

@wawammm

Hi!

For what I have read about directadmin, it will set a normal cronjob, so if I correctly interpreted the question yes, I think my reply answers to his question: in the first case the example timeouts after 1 second, in the second case it will timeout after the system call completes, due to the usage of sleep, however, it will not end, but this is just an example.

i think he means is there a difference between http (browser) requests and cronjobs regarind max_execution_time?

There can be a difference: each SAPI has a different configuration file (the php.ini). The SAPI is the interface used to serve PHP, which in case of cronjobs is CLI (Command Line Interpreter), which is also the same environment used when you run a script from a terminal.

A cronjob, usually, does not involve a browser, but a simple script ran from a CLI environment, with the above code you can test how a system call affects the script. The system sleep command can be replaced with whatever task you prefer: like downloading a big file or something else.

The difference comes in when PHP is on a Windows server: in this case the system call will be included in the maximum execution time and can timeout easily.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.