Reputation: 1221
I want to add some 6000 lines of code in a php code for my website, running on LAMP. It's on a shared hosting $6/month.
My question is will it eatup lot of php memory?
if($id==1)
{
sprintf($url,....);
}
else
if($id==2)
.....
and so on till $id
equals 6000
Upvotes: 0
Views: 109
Reputation: 104050
Getting to $url
6000 will take much longer than getting to $url
1. Not 6000 times longer, but much longer.
I'm not so sure about the wisdom of this design, but using an array would probably allow for much faster access time:
$urls = array(1 => "http://www.foo.bar/", 2 => "http://blubber.blorp/");
sprintf($urls[$id],...);
If all the URLs start with http://
, then you could move that into your sprintf()
call to save on memory. But 6000 strings times 100 bytes per (lets assume long URLs) is still just 600,000 bytes, and some overhead it's probably chewing less than one megabyte of memory total.
Upvotes: 3
Reputation: 48897
Sure it will "eat up" memory. The parser has to load 6000 if statements, urls, etc...
Since you're on LAMP, take advantage of the M
by throwing the urls into a MySQL database and select the appropriate record based on the $id
Upvotes: 1
Reputation: 38432
It will eat up too much memory and CPU, even if "too much" is only a few kb; you can code it better than this.
Upvotes: 1