I have written the following test php code that will run a python script, note that there are 3 methods listed (all work). The last method will run the python script but does not cause the PHP page to wait for it to finished.
<?PHP
$SKU= 'asdfghyt42';
$showID = '60';
//method 1
$command='C:\Python27\python.exe python\pythontesting.py $SKU $showID';
$buffer='';
ob_start(); // prevent outputting till you are done
passthru($command);
//get the result out
$sketchfabKey=ob_get_contents();
//clean up the buffer
ob_end_clean();
echo $sketchfabKey;
/*
/method 2
$command = escapeshellcmd('C:\Python27\pythonw.exe python\pythontesting.py $SKU $showID');
$output = shell_exec($command);
echo $output;
// method 3
$command="C:\Python27\pythonw.exe python\pythontesting.py $sketchfabKey $SKU";
$out = 0;
ob_end_clean();
ignore_user_abort();
ob_start();
header("Connection: close");
echo json_encode($out);
header("Content-Length: " . ob_get_length());
ob_end_flush();
flush();
exec($command);
*/
?>
the python script will open a windows messagebox and tell you it is python script 1
import win32api
import sys
import subprocess
win32api.MessageBox(0, '1:', 'yay', 0x00001000)
p = subprocess.call([sys.executable, 'pythontesting2.py'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
print "I am alive"
Once the user clicks ok button on the message box it should run the next python script which does the same thing with the message box stating it is script 2
import win32api
import sys
import subprocess
win32api.MessageBox(0, '2:', 'yay', 0x00001000)
p = subprocess.call([sys.executable, 'pythontesting3.py'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
print "I am alive"
This is where the problem occurs. If I run the 1st python script from the python shell it works exactly as intended and give me a messagebox with 1 and then a messagebox with 2.
However when the first python script is executed by the PHP page, python will only execute code within the 1st script and give me messagebox with a 1. When I click ok I do not get the 2nd messagebox and thus have concluded that the 2nd python script is never started.
I thought it may be a permissions issue with windows, set the python.exe's to run as administrator and made sure that all permissions were set to full control. It did not change anything.
Here is some info on the system if that will help:
Python 2.7
webserver is run locally via Apache and setup with XAMPP