Professional Web Applications Themes

How resource-intensive are these? - PHP Development

PHP-Gurus, I'm writing a fun little php script that generates a random image by stringing together 8 smaller images. It also reads lines in from several data text files and strings them together to make interesting phrases to go along with these images. My question is, how expensive are these features in terms of server load? I had to upgrade my hosting account for bandwidth earlier this month, because another little script of mine, BattleFishies ([url]http://www.gremkin.com/fishies[/url]), got popular over night and was serving up 8 gb of traffic a day. I don't imagine the same overnight success with this new ...

  1. #1

    Default How resource-intensive are these?

    PHP-Gurus,

    I'm writing a fun little php script that generates a random image by
    stringing together 8 smaller images. It also reads lines in from several
    data text files and strings them together to make interesting phrases to
    go along with these images.

    My question is, how expensive are these features in terms of server
    load? I had to upgrade my hosting account for bandwidth earlier this
    month, because another little script of mine, BattleFishies
    ([url]http://www.gremkin.com/fishies[/url]), got popular over night and was serving
    up 8 gb of traffic a day. I don't imagine the same overnight success
    with this new program, but I'm worried that if, let's say 10 people all
    try to access the program at the same time, something will snap and
    everything will come crashing down, with smoke coming out of the server
    and everything.

    The way the script is set up now, I am generating strings by grabbing
    random lines out of files using an array variable and the 'file'
    command. If I understand it correctly, this reads the whole file into an
    array. So, instead of getting a single line by printing a certain key in
    the array, is there a less resource intensive way of doing this? Would
    actually defining the arrays at the top of the script, and doing away
    with the external files, be benificial at all? Or perhaps there is a way
    to grab just one certain line number straight out of the text file and
    into a variable, without loading the whole thing into memory?

    Also, how will my host's linux server respond to lots of requests for
    the dynamic images? Will it crash? Will it just go really slow? Slow is
    ok. People can wait. I just don't want my host getting mad at me for
    bogging down their system. I know this is stretching, but is there any
    sort of way to restrain how many resources php is allowed to use at any
    given time, maybe spitting back a quick 'please try again' error message
    to the user? What tends to happen as php starts eating up resources? How
    many resources do you think this script will gobble up?

    Thanks for any and all help you can give me with this. PHP is fun, but I
    might be trying to make it do too much! :)

    Later,
    Brent
    Brent Guest

  2. #2

    Default Re: How resource-intensive are these?


    "Brent" <pulgswbell.net> a écrit dans le message de news:
    [email]c64bc6f2387df1b9376156693bb70538news.teranews.com[/email]...
    > PHP-Gurus,
    >
    > I'm writing a fun little php script that generates a random image by
    > stringing together 8 smaller images. It also reads lines in from several
    > data text files and strings them together to make interesting phrases to
    > go along with these images.
    >
    > My question is, how expensive are these features in terms of server
    > load? I had to upgrade my hosting account for bandwidth earlier this
    > month, because another little script of mine, BattleFishies
    > ([url]http://www.gremkin.com/fishies[/url]), got popular over night and was serving
    > up 8 gb of traffic a day. I don't imagine the same overnight success
    > with this new program, but I'm worried that if, let's say 10 people all
    > try to access the program at the same time, something will snap and
    > everything will come crashing down, with smoke coming out of the server
    > and everything.
    >
    > The way the script is set up now, I am generating strings by grabbing
    > random lines out of files using an array variable and the 'file'
    > command. If I understand it correctly, this reads the whole file into an
    > array. So, instead of getting a single line by printing a certain key in
    > the array, is there a less resource intensive way of doing this? Would
    > actually defining the arrays at the top of the script, and doing away
    > with the external files, be benificial at all? Or perhaps there is a way
    > to grab just one certain line number straight out of the text file and
    > into a variable, without loading the whole thing into memory?
    >
    > Also, how will my host's linux server respond to lots of requests for
    > the dynamic images? Will it crash? Will it just go really slow? Slow is
    > ok. People can wait. I just don't want my host getting mad at me for
    > bogging down their system. I know this is stretching, but is there any
    > sort of way to restrain how many resources php is allowed to use at any
    > given time, maybe spitting back a quick 'please try again' error message
    > to the user? What tends to happen as php starts eating up resources? How
    > many resources do you think this script will gobble up?
    >
    > Thanks for any and all help you can give me with this. PHP is fun, but I
    > might be trying to make it do too much! :)
    >
    > Later,
    > Brent
    there are different points in your question :
    - CPU load
    - memory load
    - bandwidth usage

    if you propose people to incoporate in there website images witch are hosted
    on you server, as it seems to be the cas with your battle tishes feature,
    it's very normal that the bandwidth usage is growing. People incorporate the
    image on their website, and each time somebody is displaying the page, you
    server is requested a 5 Kb image. if a hundred pages are using this feature
    each accessed 10 times a day, your server is requested 1000 images, 5000
    kbytes a day. You just have to multiply those numbers to get an idea of how
    much this feature costs without anybody really visiting your website.



    I you propose a feature that builds images from other images, text... as
    long as you only propose it to people visiting your website, everything
    should work fine. It's possible to measure the cost in terms of CPU and
    memory usage but this would be a bit complicated. 10 people requesting this
    feature at the same time never happens. The thing that happens is for
    example, 10 people requesting a script in the same period of time. 10
    requests in 1 second for example. Just calculate how many requests per day
    it would make : 864000 as day. If you consider that this would concern rush
    hours lets say 3 hours a day, this would still mean 108000 requests in 3
    hours. (10 x 3600 x 3). You're not going to reach that! So the question is
    not only how much does it cost to do that.

    The question is also, how many other sites (and what kind) are hosted on the
    same server ?
    If you serve for example 100 requests in the 3 rushy hours,
    Lets say that you script takes 1 second to be executed if it can use 100% of
    the ressources dedicated to web hosting.

    Lets say that 100 sites hosted on the same server proposing the same kind of
    feature.
    Then, your site would consume 100 seconds at 100% during 3 hours.

    All the sites together would require 10000 seconds during the 3 hours that
    is 3300 seconds at 100 % / hour.

    As the requests are not going regular during the 3 hours, the server is
    going to be overloaded. And people are going to wait (possibly very much)
    for their request to be treated.

    The question of memory and bandwidth can be handled the same way. I don't
    know if the way I'm thinking about it is very rigth.

    Servers that propose hosting together with other sites can not handle heavy
    features like image building. Try it, ask the server admin and don't propose
    people to use this feature on their website usin your servers resources !


    jerome Guest

Similar Threads

  1. intensive Course
    By Tsui Lai Yi in forum Adobe Acrobat Macintosh
    Replies: 2
    Last Post: May 29th, 09:31 AM
  2. DataSet too Memory Intensive!
    By ziondreams in forum ASP.NET Web Services
    Replies: 10
    Last Post: December 1st, 11:34 PM
  3. opteron or G5 for intensive work on CS
    By juliend@adobeforums.com in forum Adobe Photoshop Mac CS, CS2 & CS3
    Replies: 12
    Last Post: February 19th, 06:58 PM
  4. Data intensive web services
    By Meena in forum ASP.NET Web Services
    Replies: 4
    Last Post: October 7th, 07:17 PM
  5. Data intensive webservice
    By Meena in forum ASP.NET Web Services
    Replies: 0
    Last Post: October 3rd, 07:26 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139