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

1
  • Return 'what' ? Your php engine 'how handle bool types(include system settings)'. Can't use web service as an crontab ! Commented Jul 7, 2020 at 21:27

3 Answers 3

2
+25

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
Sign up to request clarification or add additional context in comments.

1 Comment

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.
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

3 Comments

Thanks a lot! Where is the server config file for IIS?
Is "timeout" a Linux command? Does Windows has a equivalent command?
"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 and here.
0

Check your max_input_time in php.ini

1 Comment

The max_input_time is 60000 seconds, which is long enough.

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.