cURL is making apache to consume most of the cpu

40 views Asked by At

I'm trying to interact with Whatsapp API using PHP cURL. The code is simple, send a POST request to send a message to a phone. That's it. It works, sends the message without issues. The problem begisn after that.

$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);

Normally Apache does not consume any CPU at all.

Not CPU consumption

If I run the code previously showed, it starts to increment the CPU consumption.

First run

And still growing.

Still incrementing consumption after first run

I run the same code again... and still growing.

still growing

After the 4th run

immediately after 4th run

a few seconds later

After that I need to restart the Apache server.

Is there something I can do to avoid this?

I updated WampServer to the last available update (3.3.2). I'm using Apache 2.4.58, PHP 8.3.0 and MySQL 8.2.0 on a PC Windows 10 Pro Version 22H2. The Apache server is using an SSL instaled with CertBot.

1

There are 1 answers

0
prueba prueba On

It is a problem with xDebug and PHP 8.3.*. Just disabled xDebug and everything is fine now.

Thanks to Otomatic in WampServer forum.