I have some code where I'm trying to reuse a curl context to do put requests and get requests. After each put request the get request fails with this PHP warning:
curl_exec(): CURLOPT_INFILE resource has gone away, resetting to default
I could use the PHP shutup operator, but I would rather properly reset the curl context. Does anyone know how to do this? I could also use different curl contexts, but I would rather reuse the connection since the application is sending a lot of requests. I could keep the file handle open, but that seems like a hackish solution, especially since this is all wrapped up in functions so i can call doPut, doGet, etc
$curlContext = curl_init();
$fh = fopen('someFile.txt', 'rw');
curl_setopt($curlContext, CURLOPT_URL, $someUrl);
curl_setopt($curlContext, CURLOPT_PUT, TRUE);
curl_setopt($curlContext, CURLOPT_INFILE, $fh);
curl_setopt($curlContext, CURLOPT_INFILESIZE, $size);
$curl_response1 = curl_exec($curlContext);
fclose($fh);
curl_setopt($curlContext, CURLOPT_PUT, FALSE);
curl_setopt($curlContext, CURLOPT_HTTPGET, TRUE);
curl_setopt($curlContext, CURLOPT_URL, $someOtherUrl);
$curl_response1 = curl_exec($curlContext);
Thanks.
Starting from PHP 5.5, curl_reset can be used to reset all previous set options.
For PHP < 5.5, Li-chih Wu's solution is a possible workaround.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With