2

I'm trying to run a Python script from PHP on a webserver. The script only contains one line

print "Hello, World"

and if I run it from the terminal, it takes 0.028 seconds. When I try doing this from PHP though

exec('python python_test.py');

it takes 125 seconds (but it does execute the script in the end). I read that there is an overhead because a new shell instance needs to be created whenever exec is called from php (PHP exec() performance), but that's not the problem since when I ran:

exec('echo hi');

it only took 0.013 seconds. So it's really the Python script that is running very slow. Any thoughts on how to make it faster?

I also tried the PHP commands shell_exec() and system() but they don't improve the speed.

Community
  • 1
  • 1
Nimyz
  • 339
  • 2
  • 11
  • How fast does your python script run when invoked by itself on the command line (without going through PHP)? If it turns out it's slow then we'll need to see the python script to find the bottleneck (or you could file up a profiler to find it yourself). – webbiedave Feb 03 '14 at 12:52
  • @webbiedave: that's answered in the question. – Wooble Feb 03 '14 at 12:54
  • It's the third line. 0.028 seconds. And the second line is the python script. All of it. – Wooble Feb 03 '14 at 12:56
  • Oh. You're right. I missed that. – webbiedave Feb 03 '14 at 12:57

0 Answers0