1

This is more of a theoretical question.

When I run a PHP script that does a passthru to some other program, say a Java application, let's assume that program works for 30 minutes and then ends gracefully and PHP keeps calling it in a loop every single time...

... does the time PHP stays idle waiting for Java count as execution time or as idle time?

Laurel
  • 5,965
  • 14
  • 31
  • 57
Frankie
  • 24,627
  • 10
  • 79
  • 121
  • Isn't this ridiculously easy to test yourself? Set a maximum execution time of 10 seconds then do a `passthru` call to something that takes 30 seconds to run. If the script terminates, the answer is execution time; if it does not, the answer is idle time. – Lightness Races in Orbit Jan 07 '11 at 02:25
  • BTW `popen` is better. `passthru` likes to buffer output for ever and a day, and doesn't give you many options. – Lightness Races in Orbit Jan 07 '11 at 02:27
  • @Tomalak Geret'kal It may be easy to test, but it's a good question. – goat Jan 07 '11 at 04:13

2 Answers2

3

This manual page seems to indicate that on Windows the time will count as execution time, whereas on Linux it will not.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
  • after several testing and longs weeks running CLI php programs extending over periods far above 12 hours this should be right. Haven't tested on Windows though. – Frankie Jan 20 '11 at 16:35
1

As far as I know, PHP will wait (be idle) for the output until the maximum execution time is met. Then the process will terminate.

Edit: I was wrong. PHP will hang until the program closes with the passthru function, regardless of the execution time. I miss read the documentation. See notes on http://php.net/manual/en/function.passthru.php

Colum
  • 3,844
  • 1
  • 22
  • 26
  • @Colum: I haven't found a reference to answer the specific question, but I'm leaning towards suggesting that your answer is incorrect. "The maximum execution time is not affected by system calls, stream operations etc. Please see the set_time_limit() function for more details." -- http://www.php.net/manual/en/info.configuration.php#ini.max-execution-time – Lightness Races in Orbit Jan 07 '11 at 02:27
  • http://php.net/manual/en/function.set-time-limit.php backs this up, but has a curious addendum comment implying that it's not true on Windows, without going into further detail. :( – Lightness Races in Orbit Jan 07 '11 at 02:29
  • Under notes (4th section), 2 once down. And I quote: "If a program is started with this function, in order for it to continue running in the background, the output of the program must be redirected to a file or another output stream. Failing to do so will cause PHP to hang until the execution of the program ends." – Colum Jan 07 '11 at 02:58
  • @Colum would this happen both in Linux and Windows? – Frankie Jan 07 '11 at 09:34
  • @Colum: That does not say that _execution time_ is not advanced. It just indicates that a call to a program with non-redirected output is executed synchronously, that PHP procedural execution will not continue until the call completes. See the manual page I referenced for a description of what that means for the _execution time_ property. – Lightness Races in Orbit Jan 07 '11 at 10:18