If you don't want your Mac to use too much memory, you can set a memory limit for PHP using the function:įor instance, you can set your PHP memory limit this way:Īpart from setting the limit for PHP, you can also increase this limit. Doing this makes it easier for you to check your Mac's scripts actively to find out if something is wrong as soon as possible. If not, you can send a notification email to yourself that contains relevant debugging information. If it isn't, you can continue with the execution of the script. Check if your device's memory usage is exceedingly high. For this, one thing you can do is to use a database or log file to document your device's memory usage.įor a more efficient solution, you should make PHP do the work for you. In such cases, simply checking your memory usage won't suffice. Sometimes, memory problems only occur after some time has passed or under very specific circumstances. This is especially true when your device's memory usage depends on other factors like the request string values. There might be times where you will find it too challenging to get output from the functions mentioned above. The reason for this is that this function takes an optional "boolean argument" with a false default value. You may soon discover that your device's current memory usage will go down after you unset the array while the peak usage stays the same. This time, the function will return the maximum amount of memory that a PHP script uses until you call the function. If you want to convert this amount to MB, use:Īpart from using the above functions, there is another important function you can use. If you want to convert this amount to KB, use: The function is:Īlthough this function gives back the amount of memory allotted to a PHP script, you will see the amount in bytes. To check this, PHP comes with a built-in function to return the amount of memory that's allotted to a PHP script. One thing you can do as part of the maintenance process is to check your Mac memory usage from time to time.
#Php free memory how to
How to check your usage of PHP script memory scriptĪs a Mac user, it's important for you to take care of your device to ensure that it's always running smoothly.
Also, memory-related problems can easily cause other issues. This becomes even more important in websites with high traffic where executions of concurrent scripts tend to occur. This can lead to crashes, bugs that are very difficult to find, and it might even cause Denial-of-Service attacks. Generally, this is okay because there are other more important things to consider like good practices of authentication and SQL security, for example.īut if you end up using excessive memory in your device, you can experience a number of issues. Memory efficiency is often neglected when considering the requirements of web applications. Why is it important to check a PHP script memory usage? But knowing this can be extremely useful to you, especially if you want to become a better developer. If you want to learn about PHP, script memory usage isn't one of the first things you will focus on.