Page 1 of 1
Slow PHP initialisation
Posted: Sun Feb 15, 2009 7:15 pm
by Parody
I am currently writing a server to server interface for an application and throughout developing it I have noted the 'slow' load times, I presumed they were just the delay between the data being sent and received, but I just tested something else which makes me think otherwise.
When I run a CURL request to a html page it is retrieved in approximately 0.002 seconds, but when I retrieve a php page it takes approximately 0.04 seconds. (It soon adds up when there are 20 or more requests per page).
The html page contains a short sentence and the php page echos it, no difference in data being received.
Is this due to php 'loading' times? Surely if php is running continuously then this shouldn't be happening.
I'm currently running on (mt) grid service if that helps to explain matters. If this is just the norm then I would be appreciative if you could advise me as to which other languages I can use to write an SQL data retrieval program accessible from the web (securely).
Thanks to anyone who replies

Re: Slow PHP initialisation
Posted: Sun Feb 15, 2009 7:54 pm
by Weirdan
Parody wrote:When I run a CURL request to a html page it is retrieved in approximately 0.002 seconds, but when I retrieve a php page it takes approximately 0.04 seconds. (It soon adds up when there are 20 or more requests per page).
The html page contains a short sentence and the php page echos it, no difference in data being received.
Like
?
Is this due to php 'loading' times? Surely if php is running continuously then this shouldn't be happening.
PHP interpreter has to perform certain initialization steps on each request (in addition to those steps webserver performs) - thus it won't be as fast as static html. Nevertheless I would advise you to try one of opcode caches available, like
apc,
xcache, etc.
If this is just the norm then I would be appreciative if you could advise me as to which other languages I can use to write an SQL data retrieval program accessible from the web (securely).
0.04 sec doesn't seem
very slow, especially for php installation without opcode cache. Anyway in many modern applications the bottleneck lies in the database queries, not in the language that is used to send them to the database server. Are you sure this synthetic test does actually represent load patterns you will have in your real application? I don't think so.
If you're aiming for best performance (and not for the shortest development cycle) there's a project I've seen mentioned once:
http://cppcms.sourceforge.net/wikipp/en/page/main.
Re: Slow PHP initialisation
Posted: Mon Feb 16, 2009 1:32 pm
by Parody
Without revealing too much of what my application does I can tell you that there are lots of queries being made to the server for a single page on the client server and 0.04 seconds for each page (as a fixed delay which cannot be decrease by more efficient code) soon adds up.
I haven't looked into how a cache could help my problem (I will in a minute), but surely if caches could remove this delay they would be built into php by default wouldn't they? I understand the issue now and I will look into CppCMS. I've always wanted to learn C++ and now I have a reason to.
PHP seems to be quite inefficient in the way pages are run. Interpreting each page's code as it is needed seems rather illogical and slow, isn't that the reason why most languages are compiled before running in production environments? I've read briefly about systems which can decrease PHP page running times, but surely the PHP interpreter still needs to be initialized doesn't it?
I will research all the questions I have asked above, but if you could give me a quick answer and a solution it would be much better
Thanks for you help so far Weirdan, it is greatly appreciated

Re: Slow PHP initialisation
Posted: Mon Feb 16, 2009 3:30 pm
by Weirdan
Parody wrote:I haven't looked into how a cache could help my problem (I will in a minute), but surely if caches could remove this delay they would be built into php by default wouldn't they?
Unfortunately no. I've read somewhere that PHP6 (maybe even 5.3) will ship with APC built-in and enabled, but, until recently, you had to install and configure it separately.
Here what opcode cache does - it takes file, compiled to bytecode, and stores it to shared memory segment, so on next requests PHP wouldn't need to read it from disk and compile again. This should reduce this fixed lag you're concerned about. Production servers sometimes configured so that PHP doesn't even check the file on disk for modifications and thus no disk access (which is often slow) is needed to serve the request.
I've read briefly about systems which can decrease PHP page running times, but surely the PHP interpreter still needs to be initialized doesn't it?
For sure. These RINIT & RSHUTDOWN (stands for 'Request init' and 'Request shutdown') phases help to maintain PHP's shared-nothing architecture, which, in turn, allows for better scalability. In other words, php might be slower compared to some other platform which performs initialization once on server startup (and shares state between different threads), but adding more web-servers for PHP application tends to be easier.
Re: Slow PHP initialisation
Posted: Mon Feb 16, 2009 4:05 pm
by Parody
Unfortunately I don't think I can use a cache system as I'm running on (mt) grid service (shared hosting) so I can't make any major configuration changes.
I'll probably just finish the server side and client side in php to ensure everything works as intended and then rewrite the server side (which is simple compared to the client side) in C++ with CppCMS as my framework.
Thanks Weirdan for explaining my options and I hope people will stumble upon this thread and find the same helpful answers.