How do I make python (local) run php script on a remote server?
I don't want to process its output with python script or anything, just execute it and meanwhile quit python (while php script will be already working and doing its job).
edit: What I'm trying to achieve:
(I don't plan to do anything with php output in python - python just has to upload php script and make it start working)
Hope I'm more clear now. Sorry if my question wasn't specific enough.
another edit: Also please note that I don't have shell access on remote server. I have only ftp and control panel (cpanel); trying to use ftp for it.
To run Python Script in PHP, we use “shell_exec” which returns all of the output streams as a string. The shell executes it, and the result can be returned as a string. It returns an error or no output at all if an empty value is passed.
Answer #2: Using the paramiko library – a pure python implementation of SSH2 – your python script can connect to a remote host via SSH, copy itself (!) to that host and then execute that copy on the remote host. Stdin, stdout and stderr of the remote process will be available on your local running script.
The simplest solution would be to use PHP's exec function. Of course this is with assumption that the Python code accept command line arguments and gives its output in stdout (and/or stderr). If the Python itself is another standalone web service, then the solution would be different.
os.system("php yourscript.php")
Another alternative would be:
# will return new process' id
os.spawnl(os.P_NOWAIT, "php yourscript.php")
You can check all os module documentation here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With