From 1b5f82cb521991619bd5ae26e07d8c6588e7bd18 Mon Sep 17 00:00:00 2001
From: Andreas Gohr <andi@splitbrain.org>
Date: Tue, 8 Jul 2008 22:47:03 +0200
Subject: [PATCH] Better write handling in HTTPClient

This patch takes care of a problem when sending large data to a remote server
through via HTTP. The write to a socket might not always send the whole chunk
in one piece. Now data is written in a loop until all bytes where sent to the
socket.

darcs-hash:20080708204703-7ad00-50809261df03c6c741393501d41d2beba128ac70.gz
---
 inc/HTTPClient.php | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/inc/HTTPClient.php b/inc/HTTPClient.php
index 7474e1fd8..3d843c912 100644
--- a/inc/HTTPClient.php
+++ b/inc/HTTPClient.php
@@ -231,7 +231,19 @@ class HTTPClient {
         $this->_debug('request',$request);
 
         // send request
-        fputs($socket, $request);
+        $towrite = strlen($request);
+        $written = 0;
+        while($written < $towrite){
+            $ret = fwrite($socket, substr($request,$written));
+            if($ret === false){
+                $this->status = -100;
+                $this->error = 'Failed writing to socket';
+                return false;
+            }
+            $written += $ret;
+        }
+
+
         // read headers from socket
         $r_headers = '';
         do{
-- 
GitLab