Phil
Phil

Reputation: 3648

Run (remote) php script from (local) python script

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.

Upvotes: 6

Views: 8780

Answers (3)

Mark Biek
Mark Biek

Reputation: 150889

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

Upvotes: 5

S.Lott
S.Lott

Reputation: 392010

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

Upvotes: 1

Pablo Santa Cruz
Pablo Santa Cruz

Reputation: 181460

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.

Upvotes: 6

Related Questions