I query an Oracle database using PHP but at a certain point, proba开发者_JAVA百科bly dued to the fact that the PHP code is very complex, I get a memory leak. I'm working to solve this but I ask you: if I convert all the complex PHP code to C code and I call an "exec" from PHP when needed, do I gain something in performance and memory optimization? Or is it a bad idea? And why?
If you want to rewrite the code in C, then you'd be better off writing it as a PHP module than as a standalone program called from PHP using exec().
Just a semi-related thought:
http://github.com/facebook/hiphop-php/wiki
HipHop for PHP transforms PHP source code into highly optimized C++. It was developed by Facebook and was released as open source in early 2010.
Generally speaking, you will lose performance since the system has to spawn another process and wait for it to terminate before it gets back to your PHP script. Memory leaks in PHP are something I rarely see, although they can happen. It can also be the underlying C wrapper that leaks memory (the Oracle DB wrapper, per example). Installing a debugger like Xdebug can help you find the cause of this leak.
I suggest you read: Finding cause of memory leaks in large PHP stacks.
PHP 5.3 also introduced a garbage collector.
Any complexity is relative. If you can't break down a complexity, writing it in another form or language doesn't help.
In short: can't answer without some context.
精彩评论