Reputation: 11
I am trying to figure out if there is a way to do a curl post, but without receiving the response.
I know I can prevent the response from being displayed by setting CURLOPT_RETURNTRANSFER
to false, but I don't even want to receive it.
I am working on a proxy and need to do the post request to a webservice, but the response it gives is MASSIVE and ends up timing out my connection (even when set to 200 seconds).
Even if it did work, that's just way too long since I don't care what the response is at all.
I can't seem to find a way to do this.
Upvotes: 0
Views: 1873
Reputation: 3820
Try using a socket rather than using cURL:
$requestBody = 'myparams=something&something=somethingelse';
$socket = fsockopen("mysite.com", 80, $errno, $errstr, 15);
if (!$socket) {
// Handle the error, can't connect
} else {
$http = "POST /path/to/post/to HTTP/1.1\r\n";
$http .= "Host: mysite.com\r\n";
$http .= "Content-Type: application/x-www-form-urlencoded\r\n";
$http .= "Content-length: " . strlen($post_data) . "\r\n";
$http .= "Connection: close\r\n\r\n";
$http .= $requestBody . "\r\n\r\n";
fwrite($socket, $http);
fclose($socket);
}
This will submit the POST request and not wait around for the response.
Upvotes: 3