Exceeding memory issues on server using PHP
<p>PHP has memory limits set at a global level in the PHP.ini file. I also know that they can be configured at the local level.</p>

<p>Our memory limit for a query is set to 132MB, but we keeping getting errors like this:</p>

<p><code>Fatal error: Allowed memory size of 161480704 bytes exhausted (tried to allocate 32 bytes) in #{removed_file_path}/script.php on line #{line}
</code></p>

<p>Currently, we are monitoring our systems through an errror log file, that caches errors while users are browsing a page, as well as using <code>cron</code>; however, these don't get logged anywhere.</p>

<p>The error can be fixed by changing any calls to <code>mysql_query</code> to <code>mysql_unbuffered_query</code>, however I need to know where this needs to be changed for all files on the server. If the script is actually not having memory issues, then I don't want to change the code since I want the server to read the results to RAM wherever possible.</p>

<p>We don't want to increase our memory limit in PHP since our host advises us against that.</p>

<p>What can be done to fix the memory issues? We are running on CentOS 6.7.</p>