给出一个Perl客户端,该客户端使用HTTP::Request向Web服务器发出请求,如下所示:
$request = new HTTP::Request('POST', $someurl);
$response = $ua->request($request);
我们正在尝试捕获/捕获致命的运行时错误,这些错误可能是由内存或时间不足的PHP脚本产生的。例如:
Fatal error: Allowed memory size of xxxx bytes exhausted
(tried to allocate xx bytes) in /xxx/xxx.php on line xx
如果调用是通过浏览器进行的,则PHP错误消息将在页面末尾结束,并且在文档源和DOM中可见:
<b>Fatal error</b>: Allowed memory size of xxxx bytes exhausted
(tried to allocate xx bytes) in <b>/xxx/xxx.php</b> on line <b>xx</b><br />
但是当在perl中分析调用的$ response时,错误消息在$response->content或$response->as_string的输出中都不可见。流基本上在错误消息之前“中断”:
HTTP/1.1 200 OK
Cache-Control: no-cache
Connection: Upgrade, close
Date: Wed, 27 Jun 2018 07:40:52 GMT
Pragma: no-cache
Upgrade: h2,h2c
Server: Apache/2.4
Content-Type: text/html; charset=UTF-8
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Client-Date: Wed, 27 Jun 2018 07:42:25 GMT
Client-Peer: xxxx
Client-Response-Num: 1
Client-SSL-Cert-Issuer: xxxx
Client-SSL-Cert-Subject: /CN=www.xxxx.ch
Client-SSL-Cipher: xxxx
Client-SSL-Socket-Class: IO::Socket::SSL
Client-Transfer-Encoding: chunked
Set-Cookie: sid=xxxxxx; path=/
Title: xxxxxxx
<!DOCTYPE HTML>
<html>
<head>
<title>xxxxx</title>
</head>
<body>
<div id="xxxx">
<div id="xxxx"><img src="xxxx"></div>
<div id="xxxx"><div id="xxxx">xxxx</div>
<div id="xxxx">
<div id="xxxx">
<b>stream</b>
marker 1
marker 2
marker 3
marker 4
marker 5
问题在于所有状态代码或错误标志(请参见HTTP::Response)看起来都正常,因为响应已开始正确流式传输。
有人可以详细说明如何从HTTP:Request或HTTP::Response内捕获此类错误吗?