I query an Oracle database using PHP but at a certain point, probably 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?
-
4Guess that depends if your C code also has a memory leak. Let's see the PHP code in question. Perhaps it can be fixed.webbiedave– webbiedave2010-11-02 17:02:14 +00:00Commented Nov 2, 2010 at 17:02
-
4It's a bad idea. If you cannot write proper PHP, you will suffer in C.Nicolas Viennot– Nicolas Viennot2010-11-02 17:14:15 +00:00Commented Nov 2, 2010 at 17:14
-
Hey, who says I can't write proper PHP (or even C)???Lotus1– Lotus12010-11-02 17:45:06 +00:00Commented Nov 2, 2010 at 17:45
4 Answers
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().
1 Comment
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.
2 Comments
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.