12 Replies - 3397 Views - Last Post: 13 March 2011 - 08:31 AM Rate Topic: -----

#1 aaron1178   User is offline

  • Dovakiin, Dragonborn
  • member icon

Reputation: 170
  • View blog
  • Posts: 1,311
  • Joined: 22-October 08

Php - how to code to reduce server load

Posted 23 February 2011 - 02:37 PM

Hey all,
I know i am a good coder but i would like to know how it is possible to reduce server load? Just to make sure that i am efficiently running my site.

Thanks in advance

Thanks,
Aaron1178
Is This A Good Question/Topic? 0
  • +

Replies To: Php - how to code to reduce server load

#2 calebjonasson   User is offline

  • Enter Title Here
  • member icon

Reputation: 209
  • View blog
  • Posts: 989
  • Joined: 28-February 09

Re: Php - how to code to reduce server load

Posted 23 February 2011 - 02:49 PM

Did you want an answer as to web development in general as to how to optimize what is loading and when it loads or because you are posting in the PHP section I assume you are more wanting to know about overhead and resource management when it comes to running web applications your servers.
Was This Post Helpful? 0
  • +
  • -

#3 aaron1178   User is offline

  • Dovakiin, Dragonborn
  • member icon

Reputation: 170
  • View blog
  • Posts: 1,311
  • Joined: 22-October 08

Re: Php - how to code to reduce server load

Posted 23 February 2011 - 03:04 PM

I've been developing with php for 5 years almost and i have never needed to reduce server load. But i think it will be easy enough to implement a system to reduce server load.
Was This Post Helpful? 0
  • +
  • -

#4 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3837
  • View blog
  • Posts: 13,997
  • Joined: 08-August 08

Re: Php - how to code to reduce server load

Posted 23 February 2011 - 05:52 PM

  • Reuse code where ever possible. Frequently used code is more likely to be in the cache, so if you can generalize your functions you should get better performance.
  • Make use of Ajax. If the browser is doing most of the work, the server isn't! Ajax also allows the server to respond for a small part of the page instead of rebuilding the entire page.

Was This Post Helpful? 2
  • +
  • -

#5 aaron1178   User is offline

  • Dovakiin, Dragonborn
  • member icon

Reputation: 170
  • View blog
  • Posts: 1,311
  • Joined: 22-October 08

Re: Php - how to code to reduce server load

Posted 10 March 2011 - 11:42 PM

ok so i would like to know? For my site i have html and javascript for my site, its pretty awsome right now but how much would it be using the server. Only html and javascript.
Was This Post Helpful? 0
  • +
  • -

#6 codeprada   User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 963
  • View blog
  • Posts: 2,382
  • Joined: 15-February 11

Re: Php - how to code to reduce server load

Posted 11 March 2011 - 05:48 AM

Pages that don't update very often should be cached.

Let's say you have a page called artist.php that upon loading it retrieves all the artists and their songs from a database. Now let's also say you average about 10 hits a day...doesn't seem like much work for the server right? But what if you average 10,000 hits or more a day then you will start to see the difference.

Each day you can create a new cache or upon say every 100 loads if you haven't added any new artists or songs and this will be stored in a HTML file so that the server doesn't have to interpret the PHP, retrieve data from the database and still execute the PHP script each time it's fetched.

the functions cache_not_expired() && page_not_loaded_100_times() are functions for you to implement. check out filectime()
http://www.php.net/m...n.filectime.php

//artist.php
<?php
//just an example
if(file_exists("artist.html") && cache_not_expired() && page_not_loaded_100_times()) {
     echo file_get_contents("artist.html");
     exit();
}

function cache($page) { 
    file_put_contents("artist.html", $page);
    return $page;
}
ob_start('cache');
?>
<html>
<head>Artists</head>
<body>
<!-- do whatever here -->
</body>
</html>
<?php
ob_end_flush();
?>


Was This Post Helpful? 3
  • +
  • -

#7 RyanRobinson   User is offline

  • D.I.C Head
  • member icon

Reputation: 39
  • View blog
  • Posts: 227
  • Joined: 31-March 10

Re: Php - how to code to reduce server load

Posted 12 March 2011 - 11:08 AM

If your website offers a search facility. Add a MySQL index to the column of data that will be searched.

For example, if you have a book catalogue and add an index on the book title column that allows MySQL to search the first 20 characters, any search queries will be limited to the first 20 characters of the book title and not the whole string.
Was This Post Helpful? 0
  • +
  • -

#8 aaron1178   User is offline

  • Dovakiin, Dragonborn
  • member icon

Reputation: 170
  • View blog
  • Posts: 1,311
  • Joined: 22-October 08

Re: Php - how to code to reduce server load

Posted 12 March 2011 - 05:22 PM

For one, i thank you for your replies. But you musn't of read my last post right. I asked if a html and javascript site, no php would use alot of server usage. An p.s i've been developing in php and mysql for over 5 years now, i pretty much know how to do search engines and all that. Thanks for your replies.
Thanks,
Aaron1178
Was This Post Helpful? 0
  • +
  • -

#9 calebjonasson   User is offline

  • Enter Title Here
  • member icon

Reputation: 209
  • View blog
  • Posts: 989
  • Joined: 28-February 09

Re: Php - how to code to reduce server load

Posted 12 March 2011 - 05:30 PM

If you just want to know about server load for an HTML/JS site then you are in the wrong section of the website.
It is also rather straight forward. If you are just loading html and javascript files you are going to have hardly any server load.
Was This Post Helpful? 1
  • +
  • -

#10 aaron1178   User is offline

  • Dovakiin, Dragonborn
  • member icon

Reputation: 170
  • View blog
  • Posts: 1,311
  • Joined: 22-October 08

Re: Php - how to code to reduce server load

Posted 12 March 2011 - 06:51 PM

i know this is in the wrong place, but i have a tenancy not to clog the forums up when i can post it in the topic i have open. I know the rules
Was This Post Helpful? 0
  • +
  • -

#11 KingCuddles   User is offline

  • D.I.C Regular

Reputation: 176
  • View blog
  • Posts: 496
  • Joined: 20-December 08

Re: Php - how to code to reduce server load

Posted 12 March 2011 - 07:43 PM

View Postcalebj, on 13 March 2011 - 12:30 AM, said:

If you just want to know about server load for an HTML/JS site then you are in the wrong section of the website.
It is also rather straight forward. If you are just loading html and javascript files you are going to have hardly any server load.



^^ This.

Unless you are running Facebook - your HTML/Javascript is going to put very little load on any server.
Was This Post Helpful? 1
  • +
  • -

#12 Dormilich   User is online

  • 痛覚残留
  • member icon

Reputation: 4278
  • View blog
  • Posts: 13,571
  • Joined: 08-June 10

Re: Php - how to code to reduce server load

Posted 13 March 2011 - 02:53 AM

you can avoid server load for CSS and Javascript if you put them in separate files. those are usually cached in the browser.
Was This Post Helpful? 1
  • +
  • -

#13 codeprada   User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 963
  • View blog
  • Posts: 2,382
  • Joined: 15-February 11

Re: Php - how to code to reduce server load

Posted 13 March 2011 - 08:31 AM

Javascript puts load on the client's browser because it is executed client side
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1