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:
- python script connects to ftp server and uploads php script (I already have this part of code)
- it runs php script (that's part of code i'm asking about)
- python script continues to do something else
- 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 script quit, php script still continues its task
(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.
-
i don't want to include it and use its output, i want to do equivalent of what happens when user enters php script's address in browserPhil– Phil2009年07月09日 14:21:25 +00:00Commented Jul 9, 2009 at 14:21
-
@Phil, please update your question to explain this more fully. The comment makes almost no sense. Python isn't a browser and won't render the HTML the way a browser would. Please provide some more detailed explanation of what you want to happen.S.Lott– S.Lott2009年07月09日 14:32:43 +00:00Commented Jul 9, 2009 at 14:32
-
ok, i edited it. i don't want to render anything. i'm not sure if i'm approaching problem correctly, but i wrote list of what i want to happen - if i can achieve it differently feel free to comment.Phil– Phil2009年07月09日 14:47:56 +00:00Commented Jul 9, 2009 at 14:47
-
@Phil: "it runs php script (that's part of code i'm asking about)" Do you want Python on your local box run some script a remote server? Is that what you're asking?S.Lott– S.Lott2009年07月09日 14:52:15 +00:00Commented Jul 9, 2009 at 14:52
-
yes, exactly (hmmmmmmmmmm 15 characters)Phil– Phil2009年07月09日 14:56:37 +00:00Commented Jul 9, 2009 at 14:56
3 Answers 3
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.
4 Comments
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
import urllib2
urllib2.urlopen("http://remotehost.com/myscript.php")
1 Comment
I'll paraphrase the answer to How do I include a PHP script in Python?.
import subprocess
def php(script_path):
p = subprocess.Popen(['php', script_path] )