首页 > 解决方案 > PHP 8.0 Curl 请求正在运行,但在日志中生成致命错误

问题描述

我在 xampp error_log (Ubuntu 20 -> /opt/lampp/logs/error_log) 中注意到:

  thrown in /opt/lampp/htdocs/core/scrapers/ps3838/ps3838.rest.php on line 106
PHP Fatal error:  Uncaught Error: Call to undefined function curl_init() in /opt/lampp/htdocs/core/scrapers/ps3838/ps3838.rest.php:106
Stack trace:
#0 /opt/lampp/htdocs/core/scrapers/ps3838/ps3838.rest.php(239): RestClient->request()
#1 /opt/lampp/htdocs/core/scrapers/ps3838/ps.scraper.php(158): Ps3838->get_odds()
#2 {main}

该错误是在我用来查询 api 的类中生成的。

if ($this->request_method === "POST") {
    $this->ch = curl_init($url);
    curl_setopt($this->ch, CURLOPT_POSTFIELDS, $param);
} else {
    $this->ch = curl_init($url."?".$param);
    curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, "GET");
}

奇怪的是代码按预期工作!没有错误,我得到了响应......发生了什么 - 为什么它被记录为错误?它怎么能抛出一个致命的错误却又完美地执行?

标签: phpcurlxampp

解决方案


推荐阅读