Re: PHP console script vs C/C++/C#

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



* at 17/04 16:30 -0500 Daniel Kolbo said:
> Hello,
> 
> I am writing a PHP script for a local application (not web/html
> based). My script is taking a longer time to execute than I want. The
> source code is a few thousand lines, so I will spare you all this
> level of detail.
> 
> I prefer to write in PHP because that is what I know best.  However, I 
> do not think there is anything inherent with my script that requires PHP 
> over C/C++/C#.

I think this points to an answer. If you're not too familiar with one
of the compiled languages then producing code that runs faster than
your current PHP implementation is a tall order. PHP, like most
scripting languages, is compiled into an internal format as a first
step and it's this that's then run. A lot of effort has gone into
making this pretty fast and by deciding to rewrite in a compiled
language you are betting that the C code, or whatever, you write will
be faster. Given the effort I imagine translating a few thousand
lines of PHP into one of the languages you name is likely to be
significant you'd want to be sure of winning that bet.

> If I wrote the console application in a c language (and compiled) would 
> one expect to see any improvements in performance?  If so, how much 
> improvement could one expect (in general)?

How long will it take you to convert the program? How much more time
will you spend on support and bugfixing?

> I assume because php is not compiled that this real time interpretation 
> of the script by the zend engine must take some time.  This is why I am 
> thinking about rewriting my whole script in a C language.  But before I 
> begin that ordeal, i wanted to ask the community for their opinions.  If 
> you think using a c language would suit me well, what language would you 
> recommend?

It's not real time interpretation. It's a one time parse and compile
when the script starts and then it runs the internal bytecode. If you
have APC, or some other sort of caching mechanism installed then part
of the speed up comes from caching the bytecode and saving on the
initial parse and compile phase.

As to what language then if you want to go ahead and do this you
should pick the one you know best. If you don't know any of them that
well then I really think that your time would be better spent on
optimising the existing PHP code first. Are you sure it's running as
fast as it can? Do you know where it's slow?

Rewriting it in another language really is the 50 pound lump hammer
solution to the problem if you've not tried anything else to speed it
up.

> My google and mail archive searching for this yielded mainly PHP for web 
> apps, so I am asking all of you.
> 
> My main question is, how much of an improvement in performance will one 
> see by using a compiled version of an application versus using a 
> scripted version of an application?
> 
> I looked at PHP's bcompiler, but the documentation is minimal so I am 
> hesitant to dig much deeper into that, unless someone strongly suggests 
> otherwise.

A quick look at the docs tells me that all that bcompiler will do is
save you the initial parse and compile phase and not speed up the
execution of the code.

The one thing you don't say is exactly how long is too long? Is it
hours or minutes? If it's seconds then consider, as someone has
suggested elsewhere in the thread, looking at APC as that should cut
down the start up time of the script.

HTH and apologies if none of this is news to you.

Struan

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux