How do I make python (local) run php script on a remote server?
如何使python(本地)在远程服务器上运行php脚本?
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).
我不想用python脚本或其他东西处理它的输出,只需执行它,同时退出python(而php脚本将已经在工作并完成它的工作)。
edit: What I'm trying to achieve:
编辑:我的目标是:
- python script connects to ftp server and uploads php script (I already have this part of code)
- python脚本连接到ftp服务器并上传php脚本(我已经有了这部分代码)
- it runs php script (that's part of code i'm asking about)
- 它运行php脚本(这是我要问的代码的一部分)
- python script continues to do something else
- python脚本继续执行其他操作
- python script quits (but probably php script still didn't finished its work so i don't want it to end when it'll exit python)
- python脚本退出(但是php脚本可能还没有完成它的工作,所以我不希望它在退出python时结束)
- python script quit, php script still continues its task
- python脚本退出,php脚本继续其任务
(I don't plan to do anything with php output in python - python just has to upload php script and make it start working)
(我不打算在python中使用php输出做任何事情——python只需要上传php脚本并使其开始工作)
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.
另一个编辑:请注意,我在远程服务器上没有shell访问权限。我只有ftp和控制面板(cpanel);尝试使用ftp。
3 个解决方案
#1
4
If python is on a different physical machine than the PHP script, I'd make sure the PHP script is web-accessible and use urllib2 to call to that url
如果python在与PHP脚本不同的物理机器上,我将确保PHP脚本是web可访问的,并使用urllib2调用该url
import urllib2
urllib2.urlopen("http://remotehost.com/myscript.php")
#2
5
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.
您可以在这里查看所有os模块文档。
#3
0
I'll paraphrase the answer to How do I include a PHP script in Python?.
我将解释如何在Python中包含PHP脚本的答案。
import subprocess
def php(script_path):
p = subprocess.Popen(['php', script_path] )
#1
4
If python is on a different physical machine than the PHP script, I'd make sure the PHP script is web-accessible and use urllib2 to call to that url
如果python在与PHP脚本不同的物理机器上,我将确保PHP脚本是web可访问的,并使用urllib2调用该url
import urllib2
urllib2.urlopen("http://remotehost.com/myscript.php")
#2
5
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.
您可以在这里查看所有os模块文档。
#3
0
I'll paraphrase the answer to How do I include a PHP script in Python?.
我将解释如何在Python中包含PHP脚本的答案。
import subprocess
def php(script_path):
p = subprocess.Popen(['php', script_path] )