开发者

PHP cURL post without returning page content

Is it possible to do a cURL post with PHP that will post my array of values and return only the curl_getinfo data but none of the page content? Here is an example of what I am currently using; it returns the page content into a variable.

However, every time it returns the page content it uses a lot of bandwidth. I'm trying to reduce the amount of bandwidth I use; all I really need back is the curl_getinfo data.

Would adding CURL_TIMECOND_IFMODSINCE accomplish this? (the page I'm posting to very rarely changes)

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RET开发者_StackOverflow中文版URNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, true);

$post_data = array();
$post_data["name"] = $name;
$post_data["age"] = $age;

curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$output = curl_exec($ch);
$info = curl_getinfo($ch);


curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
is used to return output
$output = curl_exec($ch);
set CURLOPT_RETURNTRANSFER to false so that it will not.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);


No. You need to have the server not report the data.

You could try adding a range request to the headers... but I doubt a dynamic page would respect that.


I don't think

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0); 

will help, because that just allows you to capture the response in a variable when calling curl_exec(). It's not going to stop the target server from replying to you when you send data.

Since you need to use POST to send your data, your only option seems to be to modify the target script so it doesn't respond with the data that is making you concerned about bandwidth. Maybe just add an optional flag to suppress the output of the script on the remote host?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜