开发者

PHP PCNTL - trustful error logging possible?

开发者 https://www.devze.com 2023-03-20 05:59 出处:网络
My current application makes an ajax call to a PHP page which makes an API request to a JSP page on our Oracle开发者_Python百科 platform. Currently the PHP script simply trusts that valid data was ret

My current application makes an ajax call to a PHP page which makes an API request to a JSP page on our Oracle开发者_Python百科 platform. Currently the PHP script simply trusts that valid data was returned from JSP and sends back a {true} json response to the ajax success handler. The ajax is setup to fail gracefully right now so it will work regardless, but it's not helpful to us.

My task is, once the jsp file is setup to throw exceptions, I will have PHP handle the exception accordingly, log the error, and return a json {false} response.

We are worried that the logging might take too long if it's too comprehensive. This process (no logging or error checking) is very fast currently and speed is a critical factor. My idea to circumvent this potential bottleneck is to tell PHP "log the error but don't wait for a confirmation that anything was logged, just return false".

I know that forking is possible with PCNTL but I'm hesitant to fork the entire process because I can see that being very memory demanding if we're forking.

Is it possible to do what I'm hoping, and how would I achieve this, even if not with PCNTL?


PCNTL would be a bad idea, as you have guessed.

Have you benchmarked what the logging performance would really be like? It's possible you are attempting premature optimization. Understandably, since it's ajax, you want to make it as responsive as possible, but if logging would introduce a 0.01 second average delay, maybe it's worth the cost.

Also make sure to benchmark the performance difference between fopen()/fwrite()/fclose() and syslog(), if using the syslog is an option.

It's very difficult to do anything asynchronously with PHP. Assuming logging in the PHP process is just too expensive, I would write a little logger in Java or something and send log messages to it via HTTP POST (for example). With a library like Log4J or Logback, half the work is already done for you, you just need to handle the incoming messages and log them in a worker thread. Because I don't think your setup is Rube Goldbergish enough already... :)

0

精彩评论

暂无评论...
验证码 换一张
取 消