Current location: Hot Scripts Forums » Programming Languages » PHP » Memory usage of a php script


Memory usage of a php script

Reply
  #1 (permalink)  
Old 11-03-06, 07:47 AM
koyote koyote is offline
New Member
 
Join Date: Nov 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Memory usage of a php script

Hi guys,

I'm struggling with an issue i couldnt find any answers by searching google.

Basically I have benchmarked two different php scripts, one that uses classes and page templating, meaning that the page to be displayed is first created from code and a template, then cached and then displayed to the user. While pretty fast, and very fast if its already cached, it takes aproximately 400kb of memory (im using the memory_get_usage function to find out how much memory is used)

The other script only uses functions and no templating at all, and has php code embedded in the html. This one, while slower in execution (time wise), takes a maximum of 150kb of memory on a run.

Note that on the script that uses classes, most of the classes are extended from parent classes.

Now my question is how important is memory usage here, i mean does php use ram or virtual memory, and how much memory is acceptable to be used for a server not to get stuck so to say.

While 400kb might not seem much, im thinking that if there are 100 users on the server at the same time, will the memory usage be 40mb?

Thanks in advance guys
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 11-03-06, 07:54 AM
odi's Avatar
odi odi is offline
Newbie Coder
 
Join Date: Oct 2006
Location: Switzerland
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
If you have 100 users there is not the simple calculation 400kb * 100, as you say there is a cache and if the code of a function is already in the memory there is no need to load it again.

I don't think this is a big issue unless you're using really memory-eating scripts that make connection to other servers, calculating pi or thing like that
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 11-03-06, 08:10 AM
koyote koyote is offline
New Member
 
Join Date: Nov 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks for the reply mate.

What confuses me with the memory_get_usage function is that it still displays 400kb of memory is used when i run an already cached page.

So the first time i run the page, i get: time of load: 0.15 seconds, memory usage: 400kb

The second time i run it, i get: 0.002 seconds time of load, memory usage: 400kb.

So basically thats why i get confused with this template caching thing.

Also if i have about 3-500 constants defined that need to be loaded every time, i see about 100kb being used by them, do arrays occupy less memory, and also are arrays faster than constants execution wise?

Cheers
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 11-03-06, 08:40 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
maybe this will disappoint you, but it's true: when you're execute some code and it uses an array of length n, it will take time n (for instance). now when you use an array of size 2n, most of the time the duration wont be 2n, but an exponential of n (nē, or more).

I'ld say: test your code. if you want to see if it will take about 40Mb when 100 users are executing your script, then simply open 100 browsers (this might be a lot of work, but with a javascript it should work). then simply see what the memory_usage is

UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
custom php script needed alley Job Offers & Assistance 5 06-30-10 03:14 AM
Submit button....can it send info to my email w/out the use of php???? lisa33 HTML/XHTML/XML 7 10-17-06 12:46 PM
PHP upload script alej469 Job Offers & Assistance 5 05-18-06 06:01 AM
PHP Membership Script sixflagsga Script Requests 1 05-19-05 06:23 PM
Where is this PHP script? wildatheart Script Requests 0 04-25-05 11:19 AM


All times are GMT -5. The time now is 12:44 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.