Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

php rather slow

Featured Replies

Hi guys

I'm just learning web development.

I have made a simple site using iframes to make a nav bar.

 

Someone suggested I try it with php as this is much better.

I agree with this in principal but decided to benchmark the site first.

 

Now loading time for mulgrewenterprises co uk/index html using iframes is 0.151seconds

loading time for mulgrewenterprises co uk/test php using php include is 0.501 seconds

 

Time to change page content when clicking on nav bar using iframes 0.041seconds

Time to change page content when accessing test2.php using php include 0.081 seconds

 

Now firstly a chunk of this extra time is added because the server is building the html file to send to the client. My server is currently running on a VPC.

I have a dedicated server to switch over to later so this delay would be reduced.

 

What concerns me is that trying this on a mobile phone (to test on a slower connection) takes over 5 seconds for the page to load. In fact it loads pretty quickly but takes a while to start loading.

I can see the advantages to php but surely it should be quicker than this

Compared to its competitors PHP is very slow, if you're application requires critical speed then you should use Python, Ruby or Perl... they're around 4 times quicker than PHP for most tasks.

 

Generally speaking though PHP isn't the weakest link in the chain when it comes to speed, usually network latency and the time it takes for other data like images,css,js transfer. Its quick enough for Yahoo, Facebook, Flickr, etc.

 

There are techniques you can use to make it go quicker, such as using an opcode cache and frontend output caching. Server specifications also play a big part in the speed of parsing PHP. Also the setup of PHP the server, e.g running FastCGI vs Apache module.

Hi guys

I'm just learning web development.

I have made a simple site using iframes to make a nav bar.

 

Someone suggested I try it with php as this is much better.

I agree with this in principal but decided to benchmark the site first.

 

Now loading time for mulgrewenterprises co uk/index html using iframes is 0.151seconds

loading time for mulgrewenterprises co uk/test php using php include is 0.501 seconds

 

Time to change page content when clicking on nav bar using iframes 0.041seconds

Time to change page content when accessing test2.php using php include 0.081 seconds

 

Now firstly a chunk of this extra time is added because the server is building the html file to send to the client. My server is currently running on a VPC.

I have a dedicated server to switch over to later so this delay would be reduced.

 

What concerns me is that trying this on a mobile phone (to test on a slower connection) takes over 5 seconds for the page to load. In fact it loads pretty quickly but takes a while to start loading.

I can see the advantages to php but surely it should be quicker than this

 

Using includes always adds abit of slow down, but never really thought it should be that much

Compared to its competitors PHP is very slow, if you're application requires critical speed then you should use Python, Ruby or Perl... they're around 4 times quicker than PHP for most tasks.

 

Generally speaking though PHP isn't the weakest link in the chain when it comes to speed, usually network latency and the time it takes for other data like images,css,js transfer. Its quick enough for Yahoo, Facebook, Flickr, etc.

 

There are techniques you can use to make it go quicker, such as using an opcode cache and frontend output caching. Server specifications also play a big part in the speed of parsing PHP. Also the setup of PHP the server, e.g running FastCGI vs Apache module.

From what i read facebook actually has a tool that takes php code and transfers it into fast running c++ code

I tried a few speed checks between both versions.

 

On average:

- the index.php file loaded in about 0.225 seconds

- the index.html file loaded in about 0.200 seconds

 

However, that was with the welcome.html page cached. If I cleared that cache, the index.html took about 0.430 seconds to load pulling in the welcome.html iframe.

 

 

What's the PHP code you're using to include the nav?

  • Author

I tried a few speed checks between both versions.

 

On average:

- the index.php file loaded in about 0.225 seconds

- the index.html file loaded in about 0.200 seconds

 

However, that was with the welcome.html page cached. If I cleared that cache, the index.html took about 0.430 seconds to load pulling in the welcome.html iframe.

 

 

What's the PHP code you're using to include the nav?

 

yes initiall I made the nav in index.html and then just changed the iframe to change the content. After some advice I tested it with php. The nav is in header.php and then test.php contains everything in welcome.html

  • Author

This is currently runing on a VPC. I have a dedicated server to switch over to when I'm ready.

Using php also solves an issue where the pages are not printabe, (they show each *.html on a seperate page when used in an iframe)

I'm tempted to just go with php but it makes the site feel really sluggish on a slow connection.

 

I've just tried assigning a second CPU core to the server and doubling the RAM. Not a proper indication of how moving to a real server will run but....

 

cache cleared

index.html loaded in 0.169

servcing.html loaded in 0.101

 

cache cleared

test.php loaded in 0.437

test2.php loaded in 0.135

 

This is hardly conclusive but its a bit quicker.

mobile took 31seconds aprox to load the php loads the html in less than a second

OK I'll bite...

 

Why for love of (insert diety of choice) are you using iframes to make the nave bar?

  • Author

OK I'll bite...

 

Why for love of (insert diety of choice) are you using iframes to make the nave bar?

 

please re-read the second line in my original post.

 

I'm just learning web development

 

From this, and the fact I'm posting about alternatives, one can deduce that I did not know better and I am now trying to rectify that.

  • Author

Compared to its competitors PHP is very slow, if you're application requires critical speed then you should use Python, Ruby or Perl... they're around 4 times quicker than PHP for most tasks.

 

Its not really critical that it runs fast but I think the time it takes to load on a slow connection (eg mobile phone) makes it seem really unprofessional. It agrovates me no end sitting waiting for web pages to load on my mobile. I may at some point need php but as it stands at the moment my website is much faster without it.

 

Yeah they have their own compiler - https://github.com/f...iphop-php/wiki/

 

That looks promising. Have you used it?

Havent tried hiphop yet, dont feel the need to at the moment my site loads up in 0.5s, which IMO is really fast for a website. I'm heavily using PHP (Zend Framework & Doctrine) on my site.

 

Maybe you should try pasting some of your code to see if its possibly that thats causing it to go slow?

Alternatives...

 

One trick to improve page re-loading time is to keep the static page content, menus,javascript, text content and even images in the client side storage area as opposed to the web browser cache where it cannot be easily cleared by a user. Few users actually clear the browser cache though so this method remains largely overkill.

 

Anyhow, 'cold cache' or first visit loading times are always going to be poor, more so if he page relies on PHP server side pre-processing to generate dynamic content or as in your case assemble the page. CSS should also be used wherever posibble to replace all or part of images such as the banner [1105x179px] most of which is just white. It's all about the amount of data required to be sent between request and first view.

 

The secret is to make the landing page relatively simple (and therefore faster loading) then dynamically swapping html once the page has loaded inside a hidden div to preload content into the browser cache during that couple of seconds the user is deciding what button to press next.

  • Author

Anyhow, 'cold cache' or first visit loading times are always going to be poor, more so if he page relies on PHP server side pre-processing to generate dynamic content or as in your case assemble the page. CSS should also be used wherever posibble to replace all or part of images such as the banner [1105x179px] most of which is just white. It's all about the amount of data required to be sent between request and first view.

 

The secret is to make the landing page relatively simple (and therefore faster loading) then dynamically swapping html once the page has loaded inside a hidden div to preload content into the browser cache during that couple of seconds the user is deciding what button to press next.

It hadnt occured to me yet that I could pretty much halve the banner image. Thanks for the tip. Preloading is a little above my head at the moment.

 

Havent tried hiphop yet, dont feel the need to at the moment my site loads up in 0.5s, which IMO is really fast for a website. I'm heavily using PHP (Zend Framework & Doctrine) on my site.

 

Maybe you should try pasting some of your code to see if its possibly that thats causing it to go slow?

 

Ah yeah it hadnt occured to me that now I've put it in a php file you wont be able to see the code on the website.

 

Had to trim some of the links because I cant post them yet, but this is pretty much the whole file

header.php

<body>
<div id="page-background"><img id="page-background" src="images/banner.gif">
</div> 

<a href="index.html" CLASS="Set1" target="_parent">
<div id="bannerh1">Mulgrew Enterprises</div>
<div id="bannerh2">For Everything IT at Home and at Work</div>
</a>

<table id="topnav">
<tr>
<td id="tdtopnav" align="left">
<a class="topnav" href="index.html" target="_parent">HOME </a>
<a class="topnav" href="servicing.html">Servicing </a>
<a class="topnav" href="downloads.html">Downloads </a>

</td>
<td id="tdtopnav" align="right">
<a class="topnav" href="work.html">ME@WORK</a>
<a class="topnav" href="home.html">ME@HOME</a>
<a class="topnav" href="contact.html" style="word-spacing:5;">Contact Us</a>
</td>
</tr>
</table>
</body>

 

test.php - php is on line 7

<HTML>
<head>
<title>Mulgrew Enterprises</title>
<link rel="stylesheet" type="text/css" href="theme.css" />
</head>

<?php include("header.php"); ?>

<body id="content">

<br>
<a href="test2.php"> Go To test2</a><br>
Mulgrew Enterprises pride ourselves in our excellent service and great value.<br>
We also make a big point to enable our customers to make educated choices that will suit them rather than pushing you towards our favourite products or services<br>
<br>
So here is your first choice, which best suits you.
<a href="work.html">Mulgrew Enterprises @ Work</a>
     
<a href="home.html">Mulgrew Enterprises @ Home</a>
<br><br><br><br>
<hr size=5 noshade color=black>
Or are you the adventurous type seeking our sponsored gaming team<br>
<a href="indexmega.html" target="_parent">MEGA: Mulgrew Enterprises Gaming Association</a>
</body>
</html>

  • Author

Cutting down the gif from 1100px wide to just 450 had very little effect on size. its reduced from 2.32kb to 2.27kb probably because its just 2 colours

Cutting down the gif from 1100px wide to just 450 had very little effect on size. its reduced from 2.32kb to 2.27kb probably because its just 2 colours

 

Mmmmm only php u have is one include file, idk why it would be taking longer to exicute but you may wanna start out with some xhtml standards, you have no doctype nor are you using xhtml, although idk if that would make a difference in speed

What concerns me is that trying this on a mobile phone (to test on a slower connection) takes over 5 seconds for the page to load. In fact it loads pretty quickly but takes a while to start loading.

I can see the advantages to php but surely it should be quicker than this

Apologies if I've missed something, but you're basically saying that your page is loading via the PHP in a reasonable time on a fixed line but taking a long time on a mobile? Whatever device you use to access your server makes NO difference to the time PHP will take to process and deliver that page - that's purely down to server hardware and software optimisations.

 

I ran this test: http://tools.pingdom.com/fpt/?url=mulgrewenterprises.co.uk

 

Results shifted between good (200ms for the HTML) and slow (1s for the HTML). This might be your Internet connection (you're not running this site in a proper data centre are you?), or your hosting platform.

 

Our site is PHP based, results are fine (average 250ms for the HTML): http://tools.pingdom.com/fpt/?url=www.connetu.com

 

If it's taking a long time to load on your mobile, this is either a mobile network or client device bottleneck and has nothing to do with PHP. I find a lot of mobile Internet traffic takes a while to connect even if the downloading and page rendering is reasonably fast.

 

There's a saying: "premature optimisation is the root of all evil" in programming. Why? Because it's much better to use a language which is quick to program in (like PHP) and gets results, and then worry about where the bottlenecks are and correct them (you'll also have a much better idea where the important optimisations are needed whilst experiencing significant traffic). Until such a time that you are pushing millions of pages per hour, a small added delay will make no difference to the end user experience and will just waste a lot of your time trying to "fix". It simply doesn't make sense.

Edited by Connetu_C

  • Author

Apologies if I've missed something, but you're basically saying that your page is loading via the PHP in a reasonable time on a fixed line but taking a long time on a mobile? Whatever device you use to access your server makes NO difference to the time PHP will take to process and deliver that page - that's purely down to server hardware and software optimisations.

 

I ran this test:

 

Results shifted between good (200ms for the HTML) and slow (1s for the HTML). This might be your Internet connection (you're not running this site in a proper data centre are you?), or your hosting platform.

 

Our site is PHP based, results are fine (average 250ms for the HTML):

 

If it's taking a long time to load on your mobile, this is either a mobile network or client device bottleneck and has nothing to do with PHP. I find a lot of mobile Internet traffic takes a while to connect even if the downloading and page rendering is reasonably fast.

 

There's a saying: "premature optimisation is the root of all evil" in programming. Why? Because it's much better to use a language which is quick to program in (like PHP) and gets results, and then worry about where the bottlenecks are and correct them (you'll also have a much better idea where the important optimisations are needed whilst experiencing significant traffic). Until such a time that you are pushing millions of pages per hour, a small added delay will make no difference to the end user experience and will just waste a lot of your time trying to "fix". It simply doesn't make sense.

 

I'm only really trying it on a phone as its the best example of a slow connection I have to hand. I have previously tested it on my dads connection as thats the slowest I have regular access to at around 1MB. I am hosting this on a home server. Downstream 7.2MB upstream 1.4MB. Theres work planned in our exchange in the next few months with reports of customers getting 7-8MB upload (Not that I believe it will be that high). I will move to a better connection /datacentre as traffic forces me too.

 

That site you linked to is pretty good. Bookmarked. Its basically saying that most of the time take for the page to download is making the connection. I dont think that its a very consistant becnchmark though as I myself got a result of just over a second for the html. I have tested this 100s of times here and at other sites and never got anything near that for the HTML. Its varied a bit but not to that degree.

 

I really dont agree that about premature optimisation. Your basically saying I should just make it work and worry about performance later.

I tend to take the view that something should be designed to be fast.

Granted if I were to tell a customer it would double the cost (because of the extra time) to reduce their loading time from 1.5 seconds to 0.5 seconds they would probably say they are happy with 1.5 seconds. This isnt for a customer though. It is a learning experience as much as anything. I do not want to learn to write bad code and sort it out later. That shold be the last resort of any programmer regardless of the language/platform. The "sort it out later" attitude is why we are plagued by buggy software which will be fixed in an update.

If time constraints force me too I will conced that just making it work will be good enough but until I'm forced to give up I will persue my goal of maintaining a lighning fast load speed.

Currently the only down side I see is that google wont index me properly. That will be a concern in the future but currently isnt.

  • Author

I have just found that using 2 php includes works much better than 1 php include inserted into html

 

See this example this is test.php (previous one is above)

<?php include("header.php"); ?>
<?php include("footer.php"); ?>

 

The loading time for this was 0.126seconds Slightly longet than the plain HTML but much closer to what it should be.

Loading time on the previously mentioned benchmarking website was also significantly reduced

 

Loading time on my mobile is also very responsive.

I really dont agree that about premature optimisation. Your basically saying I should just make it work and worry about performance later.

Within reason, yes. Sensible and obvious optimisations can be made as you go - and spotting those comes with experience more than anything. If a section of code is taking a long time to process in development, then definitely correct it. But efforts are best placed in further development than worrying about milliseconds here and there. Compiling into C++ is unnecessary unless you are running a high traffic site.

 

I tend to take the view that something should be designed to be fast.

If time constraints force me too I will conced that just making it work will be good enough but until I'm forced to give up I will persue my goal of maintaining a lighning fast load speed.

PHP isn't actually that bad. As I said, our website runs code which I imagine is an order of magnitude more complex than yours, we use the standard PHP interpreter without opcode caching, and with no C++ compilation, and it's taking ~200ms to process the homepage. That's fine - with the appropriate image and CSS optimisations, the whole page loads in under a second.

 

We also recently rewrote an application from Java Enterprise (a compiled in-memory language which is nearly as fast as C++) into a PHP framework. On average, it executes at the same speed as the Java application. For maybe 10ms of additional speed, are we going to worry about writing everything in C++ (a maintenance nightmare) compared to how easy PHP is to build and maintain? Nope.

 

The fact you are experiencing long delays with PHP is not a fundamental problem with PHP itself - it's something to do with your server, connection (have you tried timing the PHP on localhost?) or your PHP code. Your code looks simple too (far simpler than most of ours does), suggesting either server configuration or connection is your issue.

  • Author

The fact you are experiencing long delays with PHP is not a fundamental problem with PHP itself - it's something to do with your server, connection (have you tried timing the PHP on localhost?) or your PHP code. Your code looks simple too (far simpler than most of ours does), suggesting either server configuration or connection is your issue.

 

From what I have seen in the last couple of days I agree there is no fundamental flaw in php.

With my own site as an example it does actually increase the time taken to load the site even when workign correctly, but only by a fraction.

It should not have the big effect it was doing.

Making the changes mentioned in my last post seems to have massively improved things its now loading in 120ms aprox. This is a little slower than the html method but not so much as I will worry about it I just tried accessing it locally and got 80ms so going over the internet is adding 40ms.

 

Now I've made the change mentioned above I can live with it. As my pages grow more complex I should start to see the benefits more.

 

To clarify test.php now contains

 

<?php include("header.php"); ?>
<?php include("footer.php"); ?>

 

theres no HTML written into it, all that is put in header and footer and it seems to have had a big impact on speed. I will spit if further into header, content and footer but essentially this works well

Edited by bigmonmulgrew

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.