Log in

View Full Version : Things consider to reduce server untlization in php



letom
03-23-2013, 07:32 PM
What are the things a programmer/developer should consider when writing php codes to reduce the usage server resources ,

djr33
03-23-2013, 09:35 PM
This is a very broad question and is difficult to answer. Please ask a more specific question.

There are many things you can do, and some things you should not do. But it depends on what you're trying to accomplish. Also, please describe your site a bit-- are you getting thousands of visitors every day? Or are you worried about the server load for just a few visitors? A site like facebook has very different concerns than a small site due to the amount of traffic-- even a tiny difference in server load is huge when multiplied out for all of the users, but it wouldn't matter on most sites.

letom
03-24-2013, 07:16 PM
@Dany..

Thanks fr your message.
Yes , I think, may be I should worry about the problem of traffic in near future. If the website have not that much of traffic, why can't we apply the logic for reducing the server resources in every application.

I think using javascript do some more things to reduce the usage of server resources. I am not looking for a detailed explanation, but for important points we need to consider when we build a huge traffic website

Beverleyh
03-24-2013, 08:35 PM
I am not looking for a detailed explanation, but for important points we need to consider when we build a huge traffic websiteJust a quick rundown of things that can make a website "lighter" and faster and therefor reduce server load. Not coding related as such, but things to bear in mind all the same.

1. Use the right image format.
2. Optimise images.
3. Use image sprites to reduce HTTP requests.
4. Substitute images for Data URIs to reduce HTTP requests - adding the image data to a CSS file instead has the benefit of making them cacheable.
5. Optimise/minify HTML, CSS and JavaScript to make the pages/files smaller - includes removing extra markup/whitespace, moving styling/presentation to external CSS to make it cacheable, and using CSS shorthand so keep it streamlined.
6. Combine multiple external CSS and JavaScript files to reduce HTTP requests.
7. Serve CSS and images from another domain/host to spread server load and make use of parallel downloading.
8. Enable gzip - htaccess or via php - you can then convert external JavaScript and CSS to php and enable gzipping inside them.
9. Set far future headers on cacheable files such as CSS, JavaScript and images.
10. Link to publicly hosted JavaScript libraries such as jQuery on Google API.
11. Disable hot linking on images/media files in case other websites are likely to link directly to them.
12. Host resources on external sites instead of your own - eg. YouTube for videos.

letom
03-26-2013, 07:35 PM
@Bever
Thanks for your message.
Which is the best following method ?
Suppose i have 4 style sheets and i combined coding of these 4 css into a 1 and calling this single big css in HTML page OR calling one style sheet in HTML page and importing remaining 3 into that 1... which is the best idea to reduce the HTTP requests.

letom
03-26-2013, 07:41 PM
Link to publicly hosted JavaScript libraries such as jQuery on Google API.
Can we trust these third parties, that they will not change the link of these publicly hosted js libs. If tmrw they are going to change the link without informing the outside world , the people who follow these links may get trapped with bad issues in the website ? eh ?

djr33
03-26-2013, 08:31 PM
Can we trust these third parties, that they will not change the link of these publicly hosted js libs. If tmrw they are going to change the link without informing the outside world , the people who follow these links may get trapped with bad issues in the website ? eh ?
Theoretically, they could change the content at any time, and in general:
1) Don't assume third-party websites will never change. They might change!
2) Don't use resources from third-party websites without permission.

But... third-party websites specifically designed for this (jQuery and Google API are good examples) will not change because they're intentionally designed to stay the same. Of course they may release an update, but that would have a new URL.


A while ago, Google offered "Google Translate API", and then they thought it was being abused so they decided to discontinue the service (note that this is a service, in addition to a script, so it likely wouldn't be a problem for a script only). But when that happened, they gave, I believe, 12 months notice to all webmasters so that they could update their sites in time.

In short: yes, you can trust these websites because they are designed to be used for this purpose. But check the TOS and other information on a different website to find out if it's the same before hotlinking there.

Beverleyh
03-26-2013, 08:45 PM
@Bever
Thanks for your message.
Which is the best following method ?
Suppose i have 4 style sheets and i combined coding of these 4 css into a 1 and calling this single big css in HTML page OR calling one style sheet in HTML page and importing remaining 3 into that 1... which is the best idea to reduce the HTTP requests.Assuming that all 4 stylesheets are being used on the majority of pages, it would be better to combine them in to 1 file rather than use @import, which has negative effects on performance. Of course you'd need to assess each website on a case-by-case basis - if you have a reasonably large CSS file that is only used in one page (eg, a gallery) then it would be better to link to that as well as the default site stylesheet, in the page that needed it, rather than impose it on the rest of your site in one massive combined file.

If you wanted to keep component CSS broken down as separate files, an alternative to @import would be to convert the CSS file to php http://css-tricks.com/css-variables-with-php/ and then use php's include() instead. At the same time you can compress http://css-tricks.com/snippets/css/compress-css-with-php/ and enable gzip in the file too with ob_start("ob_gzhandler"); http://php.net/manual/en/function.ob-gzhandler.php

Beverleyh
03-27-2013, 07:37 AM
I stumbled on an interesting IE 'quirk' this morning and given the recent talk of combining CSS files, I thought that it was appropriate to add to this thread.

IE keels over at 4096 selectors in CSS. http://www.thecssdiv.co.uk/2009/08/another-weird-ie6-bug/
A case where combining multiple stylesheets into one *could* cause problems.

So if you have a hugely massive CSS file and notice that IE isn't applying the styles towards the bottom, its actually a good idea to split it into multiple stylesheets ;)