» » Get memory usage by PHP

 

Get memory usage by PHP

Author: bamboo06 on 2-11-2014, 03:06, views: 2611

3
Use cPHP built-in function memory_get_usage () to return the PHP script is currently assigned to the amount of memory, in bytes (byte). In the WEB actual development, these functions are useful, we can use it to debug PHP code performance.
Get memory usage by PHP

memory_get_usage () function returns the memory usage, memory_get_peak_usage () function returns the memory usage peaks, getrusage () returns CUP usage. But one thing Please note that you need to run on Linux in these functions.
Here we look at an example:

echo 'Starting memory:'.memory_get_usage(), '
';
$tmp = str_repeat('hello', 1000);  
echo 'Memory after running:'.memory_get_usage(), '
'; 
unset($tmp);  
echo 'Return to normal memory:'.memory_get_usage();

Output:

Starting memory:147256
Memory after running:155456
Return to normal memory:147256

In example, we use str_repeat () the string "hello" repeated 1000 times, eventually to compare the before and after consumption of memory size. As can be seen from the above example, in order to reduce memory usage, you can use the unset () function to no longer need to use a variable to delete. Similarly there mysql_free_result () function, when we no longer need to query result set data obtained can be used to release the memory occupied by the query.
Function memory_get_usage () can also have a parameter, $ real_usage, its value is a Boolean value. If set to TRUE, the acquisition of real memory allocated by the system size. If not set or set to FALSE, will be emalloc () reports the amount of memory used.
In the actual WEB development, you can compare the level of memory for each method to choose which method to use small memory PHP memory_get_usage ().
Function memory_get_usage () returns the number of bytes (in byte (s)). The following custom function to convert the number of bytes into MB easier to read:
function memory_usage() {
	$memory	 = ( ! function_exists('memory_get_usage')) ? '0' : round(memory_get_usage()/1024/1024, 2).'MB';
	return $memory;
}

Common debugging PHP code performance detection methods are:
memory_get_usage can analyze memory footprint.
Microtime function can be analyzed using the program execution time.

Tags: memory, PHP

Category: PHP Scripts

Dear visitor, you are browsing our website as Guest.
We strongly recommend you to register and login to view hidden contents.
<
  • 0 Comments
  • 0 Articles
21 April 2017 04:49

CesMamEbra

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
Cheap Viagra Super Active pharmacie en ligne viagra en valence Kamagra Orale Buy Gelatina Class Action Suits Amoxicillin cialis price Ginette 35 No Rx Buy Cheap Viagra Fast cialis Propecia Cesare Ragazzi Dulcolax generic viagra Priligy Portugal Buy Propecia Online Uk No Prescription viagra Amoxicillin Tempature Rise Prezzi Kamagra online pharmacy Viagra Et Cialis Vision Levitra 20 Mg Prezzo Buy Viagra Order Prednisone Canada Purchasing Amoxicilina With Overnight Delivery cialis Propecia Dhea 5 Alpha Reductase

<
  • 0 Comments
  • 0 Articles
23 January 2018 23:57

Susan

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
PHP one of the fine language that you can use to develop different websites and other related applications.You become professional if you take classes from writemypaper4me because they have experience people.

<
  • 0 Comments
  • 0 Articles
24 January 2018 13:54

rolex replica watches

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
Each part of rolex replica the movement are carefully polished by hand, from the motherboard omega replica radiation guillotine, as well as polished modified clockwork drum, and the uk replica watches main substrate on the Geneva ripple pattern and concentric circular texture, small harp replica watches tourbillon Frame.

Information
Comment on the news site is possible only within (days) days from the date of publication.