如何让PHP 8.1识别curl_init?



我知道这可能看起来像已经在那里的许多问题,但我读了几十个,我仍然遇到同样的问题。我的代码在我的本地机器上运行良好,我的树莓派是由完全相同的设置脚本配置的,但它在Pi上不起作用。

我的操作系统是Raspbian 10 (Buster)内核版本5.10.103-v7l+。我正在运行PHP 8.1,以及下面命令中的其他包:sudo apt install -y php8.1-common php8.1-cli php8.1-fpm php8.1-xml php8.1-curl

php -m表示curl,php -iphpinfo()表示curl已安装并启用:

cURL support => enabled
cURL Information => 7.64.0

我知道cURL已经安装并启用了,那么我如何让我的PHP识别和使用这个包?它在我本地的Linux机器上运行得很好,但在Pi上就不行。我重新启动了我的服务器和我的整个机器,都没有什么不同。我已经运行了sudo apt update && sudo apt upgrade,所有内容都是最新版本。

我的服务器上的"有问题的"代码片段如下:

require "vendor/autoload.php";
use SymfonyComponentPantherClient;
$options = [
"--headless",
"--window-size=1200,1100",
"--no-sandbox",
"--disable-gpu",
"--disable-dev-shm-usage",
];
$query = urlencode($_GET["q"]);
$url ="/search?hl=en&tbo=d&site=&source=hp&q=".$query;
$client = Client::createChromeClient("/usr/lib/chromium-browser/chromedriver", $options, [], "http://www.google.com");
$client->request("GET", $url);

我的完整错误日志是:

*168 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught Error: Call to undefined function FacebookWebDriverRemotecurl_init() in /var/lib/jenkins/workspace/url-here.com/vendor/php-webdriver/webdriver/lib/Remote/HttpCommandExecutor.php:190
Stack trace:
#0 /var/lib/jenkins/workspace/url-here.com/vendor/php-webdriver/webdriver/lib/Remote/RemoteWebDriver.php(100): FacebookWebDriverRemoteHttpCommandExecutor->__construct()
#1 /var/lib/jenkins/workspace/url-here.com/vendor/symfony/panther/src/ProcessManager/ChromeManager.php(75): FacebookWebDriverRemoteRemoteWebDriver::create()
#2 /var/lib/jenkins/workspace/url-here.com/vendor/symfony/panther/src/Client.php(117): SymfonyComponentPantherProcessManagerChromeManager->start()
#3 /var/lib/jenkins/workspace/url-here.com/vendor/symfony/panther/src/Client.php(521): SymfonyComponentPantherClient->start()
#4 /var/lib/jenkins/workspace/url-here.com/vendor/symfony/panther/src/Client.php(273): SymfonyComponentPantherClient->get()
#5 /var/lib/jenkins/workspace" while reading response header from upstream, client: 96.244.127.121, server: url-here.com, request: "GET /googleSearch.php?q=test HTTP/1.1", upstream: "fastcgi://unix:/run/php/php8.0-fpm.sock:", host: "url-here.com", referrer: "https://url-here.com/apps/browser.html"

任何和所有的帮助将是感激的,我已经挣扎了一段时间。如果可以的话,我会避免使用curl_init(),但不幸的是,正如您所看到的,该函数是在我的项目所依赖的库中调用的。

错误日志中的这一行显示了最有可能出现的问题:

# 5/var/lib/jenkins/workspace"当读取上游响应头时,客户端:96.244.127.121,服务器:url-here.com,请求:"GET/googleSearch.php?q=test HTTP/1.1", upstream: "fastcgi://unix:/run/php/php8.0-fpm.sock:",主机:" ur-here.com ",推荐人:" https://url-here.com/apps/browser.html">

你已经安装了PHP 8.0,但是你已经为PHP 8.1安装了Curl。您需要检查您的FPM或服务器配置。

我想你用的是Nginx。如果这是正确的,那么这篇文章可能会有所帮助。具体来说,您需要查看:

  • /etc/nginx/sites-available用于检查哪个套接字被使用
  • /etc/php/版本/fpm/池。d检查哪些套接字可用

最新更新