Results 1 to 10 of 10
-
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
-
25th Dec 2009, 04:26 AM #2MemberWebsite's:
CodeSociety.netur right, i completely underestimated this, now i feel like a retard! shit. also closing mysql connections too when they are done. oh well never to late!
Thanks bro
-
25th Dec 2009, 04:51 AM #3MemberWebsite's:
warezxtc.comAlways knew about this but never bothered about it :/
-
25th Dec 2009, 06:30 AM #4Respected DeveloperWebsite's:
PlatinumW.org NexusDDL.com HD-United.org CheckLinks.org FLVD.orgUsing too much unset is not a good idea as well.
Current projects:
Megaupload Premium Multifetch Script | FF Plugin: Tinypic and Imagevenue Image Remoter
Projects in hiatus:
IPB Linkchecker Bot | VB Linkchecker Bot
-
25th Dec 2009, 07:36 AM #5OPMemberWebsite's:
litewarez.net litewarez.com triniwarez.comYes Dman but lets say you had a 20 40Mb clustors being used, im sure 14 unsets would not peak the memory and will be better all round..
the reason i tell these tales to you is alot of people leave like resources open suchs mysql cons,and file wrappers etc and they need to be unset for the better performance and cyber you should know better, treat your pc with love my friend because no matter what.. it will always be better that your girl loooolJoin 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
-
25th Dec 2009, 12:23 PM #6(╯?□?)╯︵ ┻━┻Website's:
Xenu.ws WarezLinkers.com SerialSurf.com CracksDirect.comYou'd have to have a rather large script to be honest.
I only really unset things in huge pieces of code I write. In your usual standard script that isn't made for some huge traffic site you don't really need to do it.
Dman does have a point too. If you use unset a lot it can also make code look messy and sometimes remove vars which would be useful in future.
Apart from those points though, it *can* be good practice on large scales.Projects:
WCDDL - The Professional DDL Script
Top Secret Project: In Development - ZOMG
ImgTrack - Never Have Dead Images Again!
-
25th Dec 2009, 12:31 PM #7OPMemberWebsite's:
litewarez.net litewarez.com triniwarez.comok lets say your script run in like a sequence!!
Frist you start up and load constants then a registry then DB ect.. you could unset after each sequence like this
LOAD Config/Constants
LOAD DATABASE - unset(...,...,...,...,...,);
LOAD MIAN CLASS unset(...,...,);
unset takes multiple vats so if you unset the vars after each block of code.. block as like 6 classes for a certain task im sure that would be clean and better than not using it...
Also id rather my site be the best performance than keep my code 100% clean
But both your points are rightJoin 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
-
25th Dec 2009, 03:33 PM #8Respected Developer
I used to have the habit of unset()'ing 80% of all vars i used back in the days, made the script slower instead (obviously)
-
25th Dec 2009, 07:08 PM #9(╯?□?)╯︵ ┻━┻Website's:
Xenu.ws WarezLinkers.com SerialSurf.com CracksDirect.comProjects:
WCDDL - The Professional DDL Script
Top Secret Project: In Development - ZOMG
ImgTrack - Never Have Dead Images Again!
-
25th Dec 2009, 07:12 PM #10OPMemberWebsite's:
litewarez.net litewarez.com triniwarez.comyea so the best time to use it mis only on LARGE entities then but non the less people know now that it can be REALLY Helpfull if used correctly
Join 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
themaLeecher - leech and manage...
Version 4.94 released. Open older version (or...