/    Sign up×
Community /Pin to ProfileBookmark

Variables and Server Memory

I am making a script that has a list of 600 in it.

Like this:

$schools_list = <<< SCHLIST

<option value=”54″>ACADEMIA AMERICANA</option>
<option value=”55″>ACADEMIA BELLAS ARTES GANEXA</option>
<option value=”56″>ACADEMIA BILINGUE ARABE PANAMENA</option>
<option value=”57″>ACADEMIA BILING&Uuml;E &Aacute;RABE PANAME&Ntilde;A</option>
……
…..
SCHLIST;

The thing is that the list goes all the way to 830, and it started on value=”54″, so there are a lot of schools in that list.

Does a variable like $schools_list affect server memory? If so, how much? Is there a way to get rid of it as soon as it has been used with echo $schools_list ? Should I get rid of it, or the server can do that all by itself?


________________________________________________________________

[url]http://www.carbotek.org[/url]

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@NightShift58Oct 01.2007 — As soon as the script has sent its output to the client browser, memory should be released.

If you want to "get rid" of it yourself before the page has completely processed, you could use: [b]unset($schools_list)[/b]. The benefits are questionable unless you're in the middle of a long-running script.
Copy linkTweet thisAlerts:
@rpcarnellauthorOct 01.2007 — Well I can use echo $variable and then unset($variable) just to make sure the server doesn't keep the names of 800 schools forever, which is probably unlikely.

Thanks.
Copy linkTweet thisAlerts:
@MrCoderOct 01.2007 — Nowhere near as heavy as the amount of memory that would be used when resizing an image.

But it is a good practice to free memory as NightShift said.
Copy linkTweet thisAlerts:
@NogDogOct 01.2007 — Is there any particular reason you are loading a hard-coded list of options into a string variable? If all you do is echo it, then it would be more efficient to exit out of PHP mode at that point and just have the options (and any other static text) as plain HTML.
[code=php]
<?php
// code...
?>
<option>foo</option>
<option>bar</option>
etc....
<?php
// more code...
?>
[/code]
Copy linkTweet thisAlerts:
@rpcarnellauthorOct 02.2007 — Because it is a long list of schools, and that long list of schools will be on different pages. One for physics, one for engineering, etc, etc. If you choose engineering.php, for example, and then you choose one school among the hundreds I have listed, you'll get a list of articles written solely for that chosen school.

The problem is that, at any given time, I must add or remove schools so and so. When that happens, I don't want to find myself adding-removing the same school, in, let's say twenty different categories (engineering, art, science, etc, etc). It's laziness, I know, but technology was created to make us lazy. ?
×

Success!

Help @rpcarnell spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...