2

I use shell_exec to run a Python script from command line, to test, the Python script is simply waiting for a certain time period and then return True:

def test(minutes):
   import time
   time.sleep(minutes*60)
   return True

As I've tested, if the time period is 30 minutes or 60 minutes, the result was successfully returned to PHP, however if I set it to 80 minutes, PHP received no result nor even error messages.

The max_execution_time in php.ini is 30000 seconds, which is long enough.

Environment: Windows Server 2016 Standard with IIS

PHP version: 7.3.4

Chen
  • 161
  • 1
  • 3
  • 13
  • Return 'what' ? Your php engine 'how handle bool types(include system settings)'. Can't use web service as an **crontab** ! – dsgdfg Jul 07 '20 at 21:27

3 Answers3

2

According to this answer the longer you sleep the more it is probable that you encounter issues, even though 80 minutes does look that long.

If that turns out to be indeed causing your problem here, maybe you should consider as a workaround to split the sleeping time into several blocks (say 1 minute for example):

def test(minutes):
   import time
   for k in range(minutes):
       time.sleep(60)
   return True
Gillu13
  • 898
  • 6
  • 11
  • 1
    The sleep is just to mock my long running program. The real process is that I called some long running Teradata script from Python using subprocess module, while the Python script itself is called from PHP using shell_exec. The Teradata script part is OK by testing from cmd, while If I call Python script from PHP, it will fail without result/error message if it took 70+ minutes. – Chen Jul 07 '20 at 01:06
2

Try these things,

  1. In your PHP script, Add "timeout 100m" which may increase python script execution timeout

$output = shell_exec("timeout 100m python3 longrun.py"); echo $output;

enter image description here

  1. In your Server Config file ( For Apache2 in Ubuntu, it is "/etc/apache2/apache.conf" ) change timeout to 6000, default is 300. 6000 means 6000 seconds which equals to 100 minutes

enter image description here

  • Thanks a lot! Where is the server config file for IIS? – Chen Jul 08 '20 at 23:34
  • Is "timeout" a Linux command? Does Windows has a equivalent command? – Chen Jul 08 '20 at 23:45
  • "timeout" is an Apache parameter (a server parameter). @Chen you seem to be using IIS which is another server so, even though this answer might be very useful for Apache users, I don't think it is relevant for your problem. I don't know Windows very well but maybe you should look [here](https://forums.iis.net/t/1146759.aspx?PHP+execution+timeout) and [here](https://stackoverflow.com/questions/25678787/increase-php-max-execution-time-in-iis-7-5). – Gillu13 Jul 10 '20 at 13:11
0

Check your max_input_time in php.ini

dajmund
  • 82
  • 5