The issue
I recently upgraded PHP on my server from PHP 5.6 to PHP 7.0, for some reason this has caused an incredibly long TTFB (compared to before).
Quick overview of how I set up my website
My website uses a combination of client and server side optimizations to make my run at an insane speed (average of 250ms for an initial full page load), causing as little overhead for the users as possible.
However, ever since I upgraded to PHP 7.0, the time to first byte increased from around 50ms up to anywhere from 700ms to 2000ms (which feels like an eternity compared to the load times before this).
The question
I was wondering if there are known performance issues with PHP 7.0 compared to PHP 5.6, and if so how I could fix them. Thank you for your time
Related
I have optimized performance by this documentation page:
http://symfony.com/doc/current/performance.html#optimizing-all-the-files-used-by-symfony
except parts "Caching the Autoloader with APC" and Use Bootstrap FilesĀ¶
because when calling line
include_once __DIR__.'/../app/bootstrap.php.cache';
I got an error.
But page still loads at best about 2.5 seconds even if application does nothing, just outputs small hardcoded text.
I am running php built in server like this:
php -S 0.0.0.0:8000
and version is 5.6
I know with php 7 it should be faster, but before php 7 people still used to code with php 5.6. Were they really coding and waiting 2.5 seconds for each page reload? And if application does some heavier work it then would take even more.
My machine is running on windows 7, 8 GB ram, Intel B960 processor.
Can I do something to increase load time more? I think its a waste of time to wait 2.5 seconds for each small fix because it adds up over time. I want the app to be lightning fast.
"Normal Symfony Loadtime" clearly depends on your machine. I've also noticed some high loading times in dev and localhost, whereas in dev on a server (a mid level one) I'm under 300ms per page (and even quite big ones...)
The only fix for me was to develop on a server and abandon localhost.
I rent Windows 2008 64 R2 on a shared hosting environment with the following specs:
Intel XEON E5520 # 2.27GHZ
2 GB RAM
IIS 7.5
PHP v5.4
MySQL 5.5.27
FastCGI
Normally, I develop for .NET, and my websites are working great with fast rendering times.
However, I have a couple of Wordpress sites as well, and they are rather slow compared to the .NET websites. Today, I decided to investigate this. I just installed a fresh WordPress 3.8 copy using WPI (Web Platform Installer).
The website takes about 1.1 seconds to render (so it takes 1.1 seconds before any response is returned from my web server), which is, in my opinion, really slow.
I didn't install PHP/MySQL on the server myself, but I think that the best well known practices are in place, at least FastCGI is installed.
But still, I believe that Wordpress should be performing much better, even on a WIMP environment.
So, my questions are:
Should I expect more performance with this setup on the given environment (no additional optimizations such as caching), or is 1.1 seconds of rendering time normal?
And if so, any ideas on what's going on?
Btw, I know that I can speedup Wordpress somewhat by using plugins like W3TC.
Today, I finally was able to fix my slow loading problem; until now, my Wordpress sites where still loading slowly.
By chance, I stumbled upon this article:
http://www.customfitonline.com/news/2013/6/20/solve-wordpress-on-windows-server-problems/
I was like, let's try that "Slow Page Loading" tip, change localhost to 127.0.0.1 in wp_config.php:
define('DB_HOST', 'localhost');
To
define('DB_HOST', '127.0.0.1');
Sure enough, this setting makes a HUGE difference in page loading!
I'm building a website using the FuelPHP framework, which by default prints the execution time and memory usage at the bottom of the page. Now I just noticed that on my local machine, I have a pretty small memory footprint:
Page rendered in 0.0304s using 0.721mb of memory.
I deployed exactly this site (including a snapshot of the database) to my remote test server and suddenly memory usage increases by a factor of 10:
Page rendered in 0.0963s using 7.099mb of memory.
I cannot explain such a big difference from the details of execution alone, so I think the deviation must be in the environment.
Unfortunately I'm mainly a programmer, not really a server admin, so I don't really know where to start looking. So I'm going to ask a bit of a general question, which will hopefully give me some useful pointers: where should I start looking? The code is exactly the same and as far as I am aware both machines (local laptop and remote server) are fairly standard Apache installations with PHP5. Any answers suggesting specific Apache or PHP settings that might cause this, or specific lines to search for in the logs, are welcome.
I realise this is a pretty general question that might get me some downvotes, any constructive critisism is welcomed instead. Basically, I'm at a loss where to even start looking, at the moment.
Update: I decided to first exclude the framework as the culprit, so I ran the following one-line script on both machines:
Locally I get a value of about 115, while the remote server reports about 600.
Update 2: Just noticed I'm running PHP5.5 locally but server is only at 5.3. Maybe some bug that got fixed later - will upgrade that first.
Thanks for the suggestions guys, I fixed the problem.
As noted in the update to the original post, I realised I was running PHP5.5 locally but server was only at 5.3. After some ppa-magic with apt and some help from other questions on SO I managed to install Apache 2.4 with PHP 5.5.x. Now I actually see
Page rendered in 0.0261s using 0.582mb of memory.
locally and remotely
Page rendered in 2.3184s using 1.238mb of memory.
Assuming that a factor 2 is caused by the server being 64-bit and not my development machine, I can live with the remaining difference.
Use Xdebug to find out what functions are using all your memory.
Most likely it's a bug or design flaw in the framework.
It can be difficult or even impossible to get Xdebug working depending on your server. But sometimes it's pre-installed and simple.
I run a lamp stack of a couple of application servers which used a single dedicated memcache server for hosting sessions. The problem is that the items in the cache increase in a steady almost linear pace. This worries me. I figured that when the cache fills out the oldest entries will be overwritten and there shouldn't be a problem. But it seems impossible to gain any insight in the actual usage.
The versions I use are as following:
server-side:
Ubuntu 10.04
memcached 1.4.2
application-side:
ubuntu 10.04
php 5.3.2
libmemcached-0.44
pecl memcached 1.0.2
I've also tried this setup with pecl memcached 2.0.0b1, pecl memcache 2.2.6 and build against libmemcached-0.49 of which only the last had a minor impact at all. Is this behavior normal and as intended or would this be a failure of session_destroy?
Regrettably it was my own misunderstanding of memcached which gave me a wrong impression about the behavior. After some additional research I came across two (1, 2) articles which clarified the internal workings for me.
Garbage will not be collected. This still doesn't give me insight in the actual usage but at least takes away some worries. As long as I don't get evictions it should be just fine.
There is a PHP application right now on a Linux box running under Apache with MySQL. Since we are a windows shop, management wants to get rid of the Linux box and move everything over to windows. Is there a performance difference between the two platforms? Or, is there any significant difference at all, in terms of performance or management?
Microsoft had a team help out optimising PHP for Windows, which work is part of PHP 5.3. Some figures I've seen places the performance close to PHP + Apache on a unix system. Before 5.3 (Which means currently, since 5.3 isn't out yet), performance is bad on Windows. I think there are some patches and tricks you can pull to improve it, but it's going to cost you a bit of performance. That may or may not be a problem; People have a tendency to overestimate performance.
Note that there are other reasons to use unix than just performance. Code may not be portable and even though the core php runs fairly ok, you can well get into trouble with php-extensions and third party libraries. No matter how you look at it, Windows is a second-rate system for running php on.
If your application isn't huge or get hit a couple thousand times per second, there's no difference between the two.
LAMP == WAMP in php small projects. Just install something like XAMPP if you want your environment to be as close as possible to your existing one but in Windows.
Good luck with your project!
You should consider the MS WebPI (download at www.microsoft.com/web ) which would install the entire stack for you to run PHP in IIS7 environment.
the performance is comparable for most apps.
I've just done this for the same reason. Mgt wanted to get rid of the Linux box. I was able to completely move my php application and MySQL database. It took longer for me to configure PHP for IIS than it did for me to move the existing content over.
I have found though that the IIS server is a fair bit slower when it comes to loading pages and images. Where in Linux it appeared instantaneous, in IIS it takes a half second for the page to load and another second for images.