0

I am trying to call a PHP file residing on same server as my python script . I just started with python and are not aware of the basics . I have tried with

import subprocess 
 
subprocess.call("php /path/to/your/script.php") 

But its giving file now found error how ever when I execute php /path/to/your/script.php its executing properly.

Apart from above I have tried :

cmd = "php and your file name"
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)

and variant of subprocess but of no use, any help is much appreciated. I just need to call a PHP API along with some parameters i.e.

xyz.php?name=variable&age=variable2
karnish
  • 79
  • 1
  • 10
  • Also Tried with subprocess.call(["php", "/path/file.php"]) its not giving any error but its not getting called as its not coming in access logs – karnish Sep 14 '20 at 14:03
  • If you call PHP CLI, it won't land in an access log, since it isn't routed via your httpd server. The only thing logged from the CLI would be errors (assuming correct setup). – Markus AO Sep 14 '20 at 15:17
  • Does this answer your question? [1:1 call PHP from Python](https://stackoverflow.com/questions/12536190/11-call-php-from-python) ... looking at the examples there, it seems you're missing the `[` `]`; as in, need `subprocess.call(['php', ...`. – Markus AO Sep 14 '20 at 15:17
  • Hi @MarkusAO Yes you are right , it wont land in CLI. Thanks for the clarification I tried emailing from the PHP file and its working as expected . I was previously searching in the logs but as you said it won't land in access logs. – karnish Sep 28 '20 at 05:36

0 Answers0