0

Ok, I have to ask this.

When I use shell_exec, exec or other commands to execute python code from php, my page loads 10x slower. So even in my localhost, empty pages with exec or system functions load in around 0.01 seconds while under normal circumstances this time is around 0.001 seconds. I feel more comfortable with python while trying to achieve my task (a html parser that extracts info according to my needs, find most recursive words, index them etc etc...) [1]. However, the slowness of these functions make me think again to rewrite the same class in php. Isn't there any other efficient way to execute python from php?

*[1] I prefer writing my own classes rather than 3rd party parser since they do not satisfy my needs at all.

3
  • Out of interest, why aren't you using Python for everything, then? Now it sounds like PHP is little more than a glorified Python launcher. Commented Oct 24, 2011 at 19:34
  • 1
    @chown mod_python is not the preferred way of launching Python. The preferred way is mod_wsgi Commented Oct 24, 2011 at 19:39
  • @janmoesen, Nice question :) The reason is because I am comfortable with php as well, and I am building a web application. Since php is purely built for web apps, I prefer php when hacking a website. However, for this case, I had already built the class in python months ago, before starting this web application. Also, python's lists, dicts and tuples are far more approriate to achieve my task. However, it seems like I'll have to stick php's arrays for this case, and rewrite the whole class in php :) Commented Oct 24, 2011 at 19:42

1 Answer 1

1

If you are forking a process on every page request, this is going to kill performance. Consider having your python process run as a daemon, and communicate using some sort of queuing or IPC.

Forking a process is an expensive operation and should be avoided on a per-request basis.

Suggestions for inter-process communication: gearman, zeromq, among others.

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

Comments

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.