[英]php CURL post large string
我需要使用php將大字符串(6000個字符)發布到服務器,該字符串是在php中動態創建的。
$ch = curl_init('http://localhost:8080/mypost');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$result = curl_exec($ch);
當data_string很小時,它可以正常工作,但是一旦超過數千個字符,它就會掛起。 php控制台中沒有錯誤,只是沒有完成。 有趣的是,它在Quercus PHP(它不使用libCurl而是它自己的實現)中很好地工作,但是在標准php(PHP 5.3.10-1ubuntu3.26)中不起作用。 我需要在標准php中工作。
接受服務器是JVM-Grizzly服務器。 我用Java編寫了另一個客戶端,並且可以很好地發布字符串,因此我認為問題不出在服務器上。
我看到了這篇文章( https://forums.phpfreaks.com/topic/143602-long-string-passed-to-curl-postfields-not-getting-posted/ )看起來很有希望,但無法找到可行的解決方案。
使用選項CURLOPT_BUFFERSIZE
增加默認緩沖區大小
嘗試這個:
$ch = curl_init('http://localhost:8080/mypost');
curl_setopt($ch, CURLOPT_BUFFERSIZE, 84000);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$result = curl_exec($ch);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.