1

my Python script was :

base_url = "http://server.com/sync.php?"
phone_url = "phone=%s" % "12345678"
pass_url = "pass=%s" % "xxxxxxxxx"
verif_url = "u=%s" % "12345678"
url =  base_url + "%s&%s&%s" % (phone_url,pass_url,verif_url)
req = urllib.urlopen(url)
the_page = req.read()

the url look like : http://server.com/sync.php?phone=123456781&pass=xxxxxxxxx&u=12345678

Working fine but it's very slow...

So i tried use Subprocess :

proc = subprocess.Popen("php ./sync.php", "shell=True, stdout=subprocess.PIPE)
script_response = proc.stdout.read()

How i can send the parameters? (phone, pass,u)

The content of my php file :

$username = $_GET["phone"];
$password = $_GET["pass"];
$u = $_GET["u"];

2 Answers 2

1

To provide the parameters to Popen you should store them in a list:

cmd = ["php", "./sync.php"]
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)

You can see the Popen help that the first parameter args should be a sequence of program arguments or else a single string.

Note also that you can use the cwd parameter to precise the current directory.

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

4 Comments

Ok so for my exemple cmd = ["php", "./sync.php", "?phone=%s" % phone_url "&pass=%s" % pass_url "&u=%s" % verif_url] ?
i don't know from a terminal, but from my browser : server.com/…
You cannot pass HTTP GET parameters through the PHP cli. See: stackoverflow.com/questions/4186392/…
Work with : cmd = ["php-cgi", "-f", "./codephp/sync.php", "phone=%s" % phone_u, "pass=%s" % pass_u, "u=%s" % verif_u] proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) But slower than urllib.urlopen Any idea?
0

I think you are calling the sub process incorrectly.

P.S. Don't use relative path, use absolute path.

Can you try this:

proc = subprocess.Popen("php /path/to/your/sync.php arg1 arg2 argN", shell=True, stdout=subprocess.PIPE)
script_response = proc.stdout.read()

1 Comment

i don't understand wich syntax i need use : "php /sync.php phone_url pass_url verif_url" ?

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.