2

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?

Lotus1
  • 21
  • 1

4 Answers4

7

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

Mark Baker
  • 199,760
  • 28
  • 325
  • 373
  • Hi, and thanks for your reply. The fact is that for some reasons I can't easily explain here I can't write a PHP module and I can't change memory_limit inside PHP.ini. – Lotus1 Nov 02 '10 at 17:33
1

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.

SW4
  • 65,094
  • 17
  • 122
  • 131
  • However, the entire application must be "converted", you can't simply convert individual scripts/classes; and you're limited to the modules that the good Facebook folks have rebuilt to run with HipHop – Mark Baker Nov 02 '10 at 17:22
  • Sure- its only an aside, though it is open source so you do have the optionality (if you have the knowledge) to tailor as you see fit – SW4 Nov 02 '10 at 17:23
1

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.

Community
  • 1
  • 1
netcoder
  • 61,842
  • 17
  • 117
  • 139
0

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.

Halil Özgür
  • 14,749
  • 4
  • 45
  • 55