简体   繁体   English

如何通过CURL获取PHP错误消息

[英]How to get PHP error messages via CURL

I'm writing a PHP CLI testing tool for large Websites. 我正在为大型网站编写PHP CLI测试工具。 It checks the HTTP Response Code on Websites written in PHP. 它检查用PHP编写的网站上的HTTP响应代码。 The tool works with cURL. 该工具可与cURL一起使用。 But if i get not the expected status code (expected should be 200, but I get 500), I don't know why. 但是,如果我没有得到预期的状态代码(预期应该是200,但是我得到500),我不知道为什么。 Is there a possibility to get the occurred error on the website via curl to save it in an Report or something else? 是否有可能通过curl在网站上获取发生的错误以将其保存在报告或其他内容中?

在进行实际的cURL调用之前,请先尝试使用get_headers()。

What you are looking for is the function curl_getinfo(). 您正在寻找的是功能curl_getinfo()。 You can find the documentation here: http://www.php.net/manual/en/function.curl-getinfo.php 您可以在此处找到文档: http : //www.php.net/manual/zh/function.curl-getinfo.php

The procedure is as follows: 步骤如下:

  1. Prepare curl with curl_init and save the resulting handle in a variable 使用curl_init准备curl并将结果句柄保存在变量中
  2. Send your request (as you know: if not successfull response is empty but no code) 发送您的请求(如您所知:如果未成功,则响应为空,但没有代码)
  3. Now call curl_getinfo with the handle from step one. 现在,使用第一步中的句柄调用curl_getinfo。 You should get an associative array containing all needed values for your purpose. 您应该获得一个包含所有需要的值的关联数组。 The return code you are looking for is in the index "http_code". 您要查找的返回码在索引“ http_code”中。 curl_info always fetches the data of the last request upon a handle. curl_info总是在句柄上获取最后一个请求的数据。

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM