PHP cURL, memory leak when using CURLOPT_RETURNTRANSFER

The following code is in a loop. Each loop changes $ URI to a new address. My problem is that each pass takes up more memory.

$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $URI); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, 0); $res = curl_exec($ch); curl_close($ch); 

I finally found out that if I comment on the line CURLOPT_RETURNTRANSFER, the leak will stop.

I use "CURLOPT_RETURNTRANSFER, true", so I can get the result of the cURL operation as a string for parsing. But it seems that the memory used to store this line is not processed by each pass. Can anyone suggest a way to clear this buffer and restore used memory? Is there a destructor that I could use, I tried __destruct (), but didn't seem to get the correct syntax.

Thanks C

+4
source share
1 answer

PHP version 5.1.6 seems to have memory leak problems when using "CURLOPT_RETURNTRANSFER, true" to store cURL results as a string. Upgrading to 5.3 sorted the leak for me.

thanks

0
source

Source: https://habr.com/ru/post/1332889/


All Articles