I have a gateway script that returns JSON back to the client. In the script I use set_error_handler to catch errors and still have a formatted return.
It is subject
you could get the size of the memory already consumed by the process by using this function memory_get_peak_usage documentations are at http://www.php.net/manual/en/function.memory-get-peak-usage.php I think it would be easier if you could add a condition to redirect or stop the process before the memory limit is almost reached by the process. :)