5

I understand from PHP exec() performance that running exec() creates an overhead but in large programs or websites, wouldn't it be beneficial to have parts of the backend written in another language, and have PHP call the program using exec?

For instance, I wrote/ran a test with a large amounts of string manipulation - PHP took 2.3s while Java took .52 and C++ took .33. The speed difference is already obvious. The time could be sped up even more if I multithreaded the operation. I also found that parallelism can be achieved in with something like

exec("./largeoperation > mydir/$dirname.data &"); 
//or
exec('java Backend > /dev/null 2>&1 &');

With all these benefits, other than the need to write code in another language, I fail to see why I shouldn't relegate more parts of my backend to a faster program written in a different language. Also, I know of the existence of bridges like Working with Php-Java Bridge but I'm not sure if using that would be THAT much faster than simple exec(). Does anyone have any more details on exec()?

3
  • 1
    You probably want to use a message queue and workers here instead of invoking programs via exec. I like Gearman. Commented Jan 12, 2013 at 2:54
  • Gearman is incredible. Thank you so much! Commented Jan 12, 2013 at 3:12
  • 1
    Another convert! Welcome to the cult. Lemme whip up an answer so we can close this one out. Commented Jan 12, 2013 at 3:35

1 Answer 1

4

While you could farm work out to other programs using exec and friends, the thing you're trying to do is best accomplished using a message queue system. A well-designed message queue will let you write worker programs in any language you need. They're a great solution when you need to do something in another language, environment, or server.

There are lots of message queues, but I'm a big fan of Gearman. It was built by the same folks that brought us memcached. Take a peek at the PECL extension.

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.