注意:最后的解决方案
如果我尝试执行超过1024个字符的HTTP POST,则会失败.为什么?这是一个最小的例子:
recipient.php:
1000 || strlen($HTTP_RAW_POST_DATA) > 1000) { echo "This was a triumph."; } ?>
sender.php:
$url, CURLOPT_HEADER => false, CURLOPT_CONNECTTIMEOUT => 999, CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => 1, CURLOPT_POSTFIELDS => $post_data ) ); $result = curl_exec($c); echo "{$result}\n"; curl_close($c); } for ($i=1020;$i<1030;$i++) { echo "Trying {$i} - "; try_to_post($i); } ?>
输出:
Trying 1020 - This was a triumph. Trying 1021 - This was a triumph. Trying 1022 - This was a triumph. Trying 1023 - This was a triumph. Trying 1024 - This was a triumph. Trying 1025 - Trying 1026 - Trying 1027 - Trying 1028 - Trying 1029 -
组态:
PHP Version 5.2.6 libcurl/7.18.0 OpenSSL/0.9.8g zlib/1.2.3 libidn/1.8 lighttpd-1.4.19
解
为cURL添加以下选项:
curl_setopt($ch,CURLOPT_HTTPHEADER,array("Expect:"));
原因似乎是任何超过1024个字符的POST都会导致发送"Expect:100-continue"HTTP标头,而Lighttpd 1.4.*不支持它.我找到了一张票:http://redmine.lighttpd.net/issues/show/1017
他们说它适用于1.5.
您可以通过设置显式请求标头来说服PHP的curl后端停止执行100-continue-thing:
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
通过这种方式,您可以发布请求,无论您想要多长时间,并且卷曲都不会执行双阶段发布.
我差不多两年前在博客上写过这篇文章.