Results 1 to 10 of 10
Threaded View
-
24th Dec 2009, 11:40 PM #1OPMemberWebsite's:
litewarez.net litewarez.com triniwarez.comPHP TIP: Unset() : Memory Usage!
This is just a tip for when your building your applications in PHP and why you should use the unset() function.
For unset there are 2 main reason why you would use such a command.
- To unset a variable so you can redeclare it later as a fresh variable!
- Reduce memory usage dure the execution of your script
Now the main problem in PHP scripts is keeping large variables throught the whole execution of the script, causing the script to slow down dramatically after the variable is set..
here is an example of not using unset and the ram levels changing.
PHP Code://First we check the state of the memory at the start.
echo memory_get_peak_usage() . "\n"; // 36640
/*
* as you can see above the ram usage is at 36640.. 36.6Mb
* but dont forget the 36.6Mb is also apache,mysql and other services
*/
//Lets run a test to see if we can get it to peak
$a = str_repeat("KWWHunction", 4000); // repeat a string 4000 times
//Lets check what effect that above has had on the memory usage
echo memory_get_peak_usage() . "\n"; // 60765
/*
* As you can see the memory is 60.7Mb thats 24.1Mb increase
*/
but if theres no use for $a, so lets take a look at the effect if we unset the variable after we have finished with it..
PHP Code://First we check the state of the memory at the start.
echo memory_get_peak_usage() . "\n"; // 36640
/*
* as you can see above the ram usage is at 36640.. 36.6Mb
* but dont forget the 36.6Mb is also apache,mysql and other services
*/
//Lets run a test to see if we can get it to peak
$a = str_repeat("KWWHunction", 4000); // repeat a string 4000 times
//UNSET HERE
unset($a);
//Lets check what effect that above has had on the memory usage
echo memory_get_peak_usage() . "\n"; // 38230
/*
* instead of a 24.1Mb increase we only have a 0.2Mb increase
*/
Peace outlitewarez Reviewed by litewarez on . PHP TIP: Unset() : Memory Usage! This is just a tip for when your building your applications in PHP and why you should use the unset() function. For unset there are 2 main reason why you would use such a command. To unset a variable so you can redeclare it later as a fresh variable! Reduce memory usage dure the execution of your script Now the main problem in PHP scripts is keeping large variables throught the whole execution of the script, causing the script to slow down dramatically after the variable is set.. Rating: 5Join Litewarez.net today and become apart of the community.
Unique | Clean | Advanced (All with you in mind)
Downloads | Webmasters
Notifications,Forum,Chat,Community all at Litewarez Webmasters
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
[HELP] High memory usage on the server
By damnyou in forum Technical Help Desk SupportReplies: 9Last Post: 16th Mar 2012, 09:00 PM -
To much memory usage
By WarezFreaks in forum Technical Help Desk SupportReplies: 18Last Post: 11th Aug 2010, 04:59 AM -
high memory usage help
By accyuklad in forum Hosting DiscussionReplies: 5Last Post: 6th Jul 2010, 04:45 PM -
Memory Usage
By -Im.z2ight- in forum Server ManagementReplies: 3Last Post: 21st Mar 2010, 09:08 PM -
[HOW TO]Lower Your FireFox Memory Usage
By Pyro in forum Tutorials and GuidesReplies: 12Last Post: 3rd Aug 2009, 03:38 AM
themaPoster - post to forums and...
Version 5.36 released. Open older version (or...