Jump to content

[SOLVED] Fastest Website Possible? - Optimization and PHP loading


random1

Recommended Posts

Hey All,

 

I've been optimizing my PHP code and server to cache resources correctly, enable compression etc to get my code to be prefessional.

 

I have the following results in YSlow for Firefox, running on localhost:

 

71471231.th.jpg

 

The purple is loading time.

 

Is 416ms (on average) a reasonable loading time to get resulting HTML from a PHP file for a high end enterprise application?

 

The page I'm loading is an admin page that uses a mysqli connection, around 10 queries (in prepared statements) and does quite a lot of validation.

 

What some steps you'd take to reduce this time?

Link to comment
Share on other sites

Overall, the lower the number the better. However as a matter of opinion at least. There is no standard low set. As its mostly dependent upon images, coding format, size of files being pulled in, and so on and so forth.

 

It your using HTML with a Table Based layout then the page is going to take longer to load based on the amount of code it has to run through. As well as sheer size of the file. If your running off a CSS template scheme using DIVs as your basic layout scheme its going to reduce the load time significantly. Unfortunately over all and as said as a matter of opinion its just a lot of different variables that tie into the load time. You also mentioned something about localhost. It being on your machine will increase the load time ten fold as all the files are stored locally, the sql server web server etc all run off the local machine that said the load time is as fast as your processor can handle as opposed to the bandwidth factor.. I could probably babble on and on incoherently but I wont.. either way I hope this helps a little.

Link to comment
Share on other sites

Optimization is a tricky subject.

 

You could spend hours optimizing code and / or algorithms that have a negligible measurable impact on your site's performance.

 

Performance is also closely tied to hardware and / or software settings.  So optimizations that work well on one machine may or may not carry over to another machine.

 

The most practical and realistic solution is to do the work in the simplest manner possible.

 

Test your work in an environment that replicates exactly, or as close as possible, the production environment.  If you notice certain parts of your site (i.e. a particular query, a particular segment of PHP code) are causing performance draining spikes then optimize those things only.

 

Finally deploy your work to the production environment and then continue to monitor things such as slow page loads, failed requests, long database queries, etc.

 

In short, do the work in the simplest manner possible and then optimize when and where you find it necessary.

 

(And remember that "optimization" could be as simple as upgrading the server memory, hard drives, changing the working memory of the database server, Apache settings, installing ram disks, or any other of non-programming tasks.)

Link to comment
Share on other sites

There are some optimization tricks that may give you a boost:

 

1. Minimize the number of disk operations. Accessing the filesystem and filesystem data is very slow, especially if you open many files or perform too many operations on the same file, as each access requires PHP to call a system function, and potentially - look for the data on the device.

 

The main problem with such optimization is that you should load make a more modular code and load only the necessary parts (OOP and autoloading are very helpful here). However, if a request must perform many different operations, it actually increases the amount of work, because PHP must load many smaller files then. However, such situations are rather rare, and moreover - you can install a PHP accelerator to cache the precompiled script in the memory.

 

2. Use optimal algorithms. Unsually, there are no complex algorithms when displaying a page, but sometimes the problem is more complicated and you must ensure that the used algorithm is the fastest possible one. If you have two algorithms and one of them performs in O(n) time, and the second one in O(n^2) (n - the amount of data), it doesn't matter how you optimize the second one, the first one will always be faster for almost all of the data sizes.

 

3. The same applies to the functions. For example, if you want to check, if a word "Foo" appears in the string, don't use regular expressions, but simple "strpos()". If there is a PHP function that does exactly what you want to do, use the function and do not reimplement the wheel.

 

4. Use caching and buffering the data.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.