cURL 正在使 apache 消耗大部分 cpu

问题描述 投票:0回答:1

我正在尝试使用 PHP cURL 与 Whatsapp API 进行交互。代码很简单,发送POST请求向手机发送消息。就是这样。它有效,发送消息没有问题。之后问题就开始了。

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://graph.facebook.com/v19.0/<PHONE_NUMBER_ID>/messages");
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode([
    'messaging_product' => 'whatsapp',
    'to' => '<PHONE_NUMBER_TO_SEND>',
    'type' => 'template',
    'template' => [
        'name' => 'hello_world',
        'language' => [
            'code' => 'en_US',
        ],
    ],
]));
curl_setopt($curl, CURLOPT_HTTPHEADER, [
    "Authorization: Bearer <TOKEN>",
    'Content-Type: application/json',
    ]);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($curl);
curl_close($curl);
var_dump($response);

通常 Apache 根本不消耗任何 CPU。

如果我运行之前显示的代码,它会开始增加 CPU 消耗。

并且仍在增长。

我再次运行相同的代码......并且仍在增长。

第四次运行后

之后我需要重新启动 Apache 服务器。

我可以做些什么来避免这种情况吗?

我将 WampServer 更新到最新可用更新 (3.3.2)。我在 Windows 10 专业版 22H2 的 PC 上使用 Apache 2.4.58、PHP 8.3.0 和 MySQL 8.2.0。 Apache 服务器正在使用与 CertBot 安装的 SSL。

php apache curl
1个回答
0
投票

这是 xDebug 和 PHP 8.3.* 的问题。只需禁用 xDebug,现在一切都很好。

感谢 WampServer 论坛中的 Otomatic。

© www.soinside.com 2019 - 2024. All rights reserved.