PDA

View Full Version : Random Quote script - how bad is it on a server


unconnected
05-25-2002, 02:44 PM
How much server resources does a random quote script use?
I am using one about 40 times on my page to generate random descriptions on gallery links that I have going to trades...
so that it will always change..
I want to start using it more extensively but I dont' want it to start melting my server if I put 100 instances of it on a page getting 50k a day..

Brian911
05-25-2002, 02:56 PM
depends on many factors like the size of the script, how well it is coded and of course your server.
quote scripts can be a real burner if they use several source files to generate quotes and if they use a rather complicate validation code. and 100 runs for 50k/day seems to require a lot at the first look, even at the second :)

I'd probably run the script every 30 mins or so using cronjob and have it write all quotes to text files, then read them out using ssi or something..
btw:
you could also try using javascript, never tried that before though

Zatlther
05-25-2002, 05:21 PM
I would use a php/mysql kinda script. You could get the job done with fewer problems that way. Perl accessing a few text files and then doing some processing to create the text will melt a server sooner than php/mysql doing its thing. And yeah, you can melt a server with poorly coded php or setup a perl script that is smokin hot but overall php uses less server resources. There are quite a few scripts out there you could try. Test a few to find one that does what you need.

shane
05-25-2002, 09:33 PM
javascripts the best for something like that

Wilbo
05-25-2002, 09:55 PM
Using a random quote script is a good idea for generating unique looking pages. I'm going to have to look into this also.

SexySites
05-25-2002, 10:08 PM
bit of a generalized question LOL

laters,
Chris

Cyborg
05-25-2002, 10:15 PM
I say php is better no big need for mysql actually...
If you want it done hit me on icq 19671987 i can do that for you :)

Cyborg
05-25-2002, 10:20 PM
Correction 19671897

unconnected
05-25-2002, 10:42 PM
Thought it was rather specific myself..
and I dont' need something to be going into a mysql database for something so simple, flat files are the quickest and most efficient way that I know of..

There is only one txt file that it accesses , just a list of descriptions and it picks one..
or 50 I should say..
hasn't turned my server into a puddle yet, so I am good to go..
CPU loads never really go under 90% so not too much, will experiment with it at a more extensive level..

Atahualpa
05-26-2002, 07:04 AM
I read somehwere that php should be well able to perform about 20-30 tasks per second on an average server

code||die
05-26-2002, 07:12 AM
Don't use a mysql database, don't use .txt files, just put the quotes in variables directly in the script. That way, a lot of "costly" CPU time is saved. (if done right, only 5 lines of code actually have to be executed I think)

Wilbo
05-26-2002, 09:03 AM
Does anyone know of an available script that could handle this efficiently?

code||die
05-26-2002, 09:15 AM
very simple, and not half as efficient as it could be (cos I'm lazy and making it right now):


<?php

// You can add more quotes if you want to

$quote[0] = "Blegh";
$author[0] = "Nixon";
$quote[1] = "Beer is good";
$author[1] = "Homer (Simpson)";
$quote[2] = "At your service";
$author[2] = "Pim Fortuyn";

$cnt = count($quote);
$cnt = $cnt - 1;

mt_srand(time());
$onpage = mt_rand(0, $cnt);

echo($quote[$onpage] . "<br>\n");
echo("<b>" . $author[$onpage] . "</b><br>\n");

?>

code||die
05-26-2002, 09:23 AM
Ofcourse, you add new quotes by adding:

$quote[3] = "quote here";
$author[3] = "author here";

Make sure the numbers increment with the number of the quotes you add. Also, escape things like " with an \, so instead of ", write \" in the quote.

Zatlther
05-26-2002, 09:29 AM
oops, sorry, I was thinking WAY bigger that what you need. My impression was you were growing and needed to use 50 or 150 different quotes getting proccessed a million times a day kinda thing. :)

code||die
05-26-2002, 09:32 AM
This crappy script would work with quite a nice number of quotes... it wouldn't have a problem with 100 or so

code||die
05-26-2002, 09:34 AM
Oh...wait, unconnected, you aren't looking for a random quote script, but for random descriptions on galleries...

In that case, just wait until my (completely free) tgp script comes out :)
It will have that ability, combined with that of static pages, so it wouldn't melt down your server in a million years ;)

unconnected
05-26-2002, 01:46 PM
Looking forward to that..
how long do you think until it is released?

Make sure you keep the features of AGP, because that script is pretty killer and I couldn't imagine life without a lot of the options that it offers

unconnected
05-26-2002, 01:51 PM
Looking forward to that..
how long do you think until it is released?

Make sure you keep the features of AGP, because that script is pretty killer and I couldn't imagine life without a lot of the options that it offers..

Wilbo
05-26-2002, 05:52 PM
Would the apache mod_random do this sort of thing?

http://software.tangent.org/projects.pl?view=mod_random

GFED
05-27-2002, 02:35 AM
Yeah it does take a lot on the server. I use a random link script with about 100 galleries and sometimes it locks up.

I want to list my TDCJ top list and instead of putting names of the sites, a random description. But I can't get the SSI to work inside the PHP script. What is your method? Right now all I can manage is it saying Gallery 1, 2, 3, etc...

unconnected
05-27-2002, 10:04 AM
HJeheh, well I appreciate the advice, unfortunately it was about 6 hours late as I just melted my server into a puddle of goo, not literally..

I have about 120 instances of an SSI to a random quote CGI running on a page that got 35-40k a day and the whole server just went 'bye bye'..
so my advice to anyone doing this is keep it to one instance of a CGI running or use Javascript so that it can run clientside..
CGI isn't cut out for this sort of thing :)

Wilbo
05-27-2002, 10:09 AM
Originally posted by unconnected

so my advice to anyone doing this is keep it to one instance of a CGI running or use Javascript so that it can run clientside..
CGI isn't cut out for this sort of thing :)

How is this done with javascript?

xAro
05-27-2002, 10:21 AM
Originally posted by unconnected
HJeheh, well I appreciate the advice, unfortunately it was about 6 hours late as I just melted my server into a puddle of goo, not literally..

I have about 120 instances of an SSI to a random quote CGI running on a page that got 35-40k a day and the whole server just went 'bye bye'..
so my advice to anyone doing this is keep it to one instance of a CGI running or use Javascript so that it can run clientside..
CGI isn't cut out for this sort of thing :)

SSIs are for simple operations not for a complex projects, to put 120 file includes into SSI is a very bad idea - top put 120x cgi exec into the SSI is _extremly_ bad idea, however 50k/day means over 1 visit in a 2 seconds so you should not have a problem on a dedicated server, but better idea is to create SINGLE SSI call to create your page (not 120 cgi calls - it is very irresponsible especially if proceeded on shared servers) ... and the BEST idea overall is to create a random page every, lets say, 5 minutes - almost no CPU load and effect is (as I believe) the same, i'm doing much more traffic on my servers and I don't have such problems, if page is rendered once for 5 minutes there is almost no difference on CPU load between changing 1 entinty and 1000 entities

Zatlther
05-27-2002, 11:12 AM
Originally posted by GFED
But I can't get the SSI to work inside the PHP script.

You could use virtual() in php, here is the manual page for that function.
http://www.php.net/manual/en/function.virtual.php
Even better would be to get php to generate the random descriptions, since you are
already using php.

unconnected
05-27-2002, 12:15 PM
Nah, the best idea for something this size, instead of having 120 SSI's running per server is to do something like run the script once and have it output the html to a file and then use that.
just updating it everyday or twice a day..
One operation, not 4 million :)

GFED
05-27-2002, 05:54 PM
Originally posted by Zatlther


You could use virtual() in php, here is the manual page for that function.
http://www.php.net/manual/en/function.virtual.php
Even better would be to get php to generate the random descriptions, since you are
already using php.


Thanks Z man!

GFED
05-27-2002, 05:56 PM
Originally posted by unconnected
Nah, the best idea for something this size, instead of having 120 SSI's running per server is to do something like run the script once and have it output the html to a file and then use that.
just updating it everyday or twice a day..
One operation, not 4 million :)

How do I get create an html page? Now I'm really confused... I know how to hack and modify, but not program from scratch. I'm just starting php, and perl. So I'm a lamer. :)

Zyber
05-28-2002, 01:54 AM
Laughing my ass of... Good entertainment :D :bounce: :bounce:

What other server melting tricks can you come up with?

I am writing a new cook book called "How to melt your server in 123 ways"