Question

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()?

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top