如何监控Opencart结帐时的虚拟内存使用情况

In a previous question I posted, I mentioned that we randomly get a 500 Internal Server Error alerts on Opencart checkout. This seems to occur on AJAX calls to a backend .php/.tpl file. The temporary solution is to reprocess the ajax when the error alert triggers. For now, the solution is working as we have yet to get a 500 Internal Server Error alert.

I am trying to look deeper into the problem. Hopefully, I can come up with a better fix.

The only lead I have is on cpanel logs. On resource monitor, the virtual memory seems to reach its limit when the error generates. On the error log, this is generaled as well:

'(12)Cannot allocate memory: couldn't create child process: /opt/suphp/sbin/suphp...'

My assumption is there could be a memory issue somewhere along the pages being called on checkout.

I've created a table log on the database and written a model (PHP) that checks the memory usage each time it's called:

class ModelToolMem extends Model {
    public function memory_usage_logs($page_route, $page_process){
       $peak = memory_get_peak_usage();
       $peak_kb = $peak/1024;
       $peak_mb = $peak_kb/1024;
       $peak_mb = number_format($peak_mb, 2, '.', ',');
       $peak_details = "peak memory usage = $peak_mb MB";
       $sql = "INSERT INTO table_memory_log (page, process, details, date_time) VALUES ('$page_route', '$page_process', '$peak_details', NOW())";
       $this->db->query($sql);
    }
}

The model gets called via scripts on each page called. A sample script is as follows:

$this->load->model('tool/res_mon');
$this->model_tool_mem->memory_usage_logs('quickcheckout/some_page', 'some_page.php > validate');

As I do a test checkout, the memory allotted to the running script is recorded on the database. The biggest memory I observed on the log is 3.00 MB, which would be normal?

However, as I finished doing a test run and checked on the cpanel logs, I saw that there were instances when the virtual memory reached its limit and this appeared in the error logs:

'(12)Cannot allocate memory...'

But when I checked on the logs in the database, I did not see any unusual increase in the memory.

What would be a better way to monitor the virtual memory usage when a PHP script is executed? Is there other PHP command aside from memory_get_peak_usage()?

Thanks