6

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.

10
  • 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 browser Commented 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. Commented 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. Commented 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? Commented Jul 9, 2009 at 14:52
  • yes, exactly (hmmmmmmmmmm 15 characters) Commented Jul 9, 2009 at 14:56

3 Answers 3

6
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.

Sign up to request clarification or add additional context in comments.

4 Comments

ok, will this kill my php script if i'll quit python while php script is still running?
Why do I need to type 15 characters when the correct answer is "yes"? :-) So: Yes, it will.
ok... see my question edit - i'm searching for something that will let php script continue its task even if python will already finish
is it possible to send value from python file to php file
5

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

Finally something useful! Will have to check if it works, but if it works it's exactly what I want to do. Thank you.
1

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] )

1 Comment

Thanks. Sorry for noob question, but since it's on remote server how do I specify path? Can it be url? Also, will php script continue working even if python will quit?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.