Uso de memoria en PHP

Cuéntalo! Share on FacebookTweet about this on TwitterShare on Google+Digg thisShare on LinkedInShare on TumblrEmail this to someone

Observar el uso de memoria para optimizar el código puede hacer que nuestro código vaya mas rápido y funcione mucho mejor.

PHP tiene un recolector de basura y un administrador de memoria bastante complejo. La cantidad de memoria que utiliza su guión puede subir y bajar durante la ejecución de un script.

Para obtener el uso de la memoria actual, podemos utilizar la función memory_get_usage(), y para obtener la mayor cantidad de memoria utilizada en cualquier momento, podemos utilizar la función memory_get_peak_usage ().

Ejemplo:

echo Initial: “.memory_get_usage().” bytes“;
/* prints
Initial: 361400 bytes
*/

// let’s use up some memory
for ($i = 0; $i < 100000; $i++) {
$array []= md5($i);
}

// let’s remove half of the array
for ($i = 0; $i < 100000; $i++) {
unset($array[$i]);
}

echo “Final: “.memory_get_usage().” bytes“;
/* prints
Final: 885912 bytes
*/

echo “Peak: “.memory_get_peak_usage().” bytes“;
/* prints
Peak: 13687072 bytes
*/

  • minecraft force op hack

    Good way of telling, and pleasant piece of writing to take facts
    about my presentation topic, which i am going to deliver in college.

  • swing copters hack

    Wow, marvelous weblog structure! How long have you ever been running a blog
    for? you make running a blog look easy. The overall glance of your website is
    great, as smartly as the content!

  • blackshot hack

    Hi, i think that i saw you visited my web site thus i came to “return the favor”.I’m attempting to find things to improve my
    website!I suppose its ok to use a few of your ideas!!

  • als charm

    Have you ever considered creating an ebook or guest authoring
    on other sites? I have a blog centered on the same topics you discuss
    and would love to have you share some stories/information. I
    know my viewers would enjoy your work. If you are even remotely interested, feel free to send
    me an email.

  • Frank Borris

    Have you ever considered writing ann ebook or guest authoring on other blogs?
    I have a blog centered on the same information you discuss
    and would really like to have you share some stories/information. I know my readers would
    enjoy your work. If you’re even remotely interested, feel
    free to shoot me an email.