Long running Python script returned no result using shell_exec in PHPGet the solution ↓↓↓
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
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
Try these things,
- In your PHP script, Add "timeout 100m" which may increase python script execution timeout
$output = shell_exec("timeout 100m python3 longrun.py");
- 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
Check your max_input_time in php.ini
People are also looking for solutions of the problem: uncaught mysqli_sql_exception
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.