@@ -62,6 +62,7 @@ protected function flush() {
6262 $ socket = $ this ->createSocket ();
6363
6464 if (!$ socket ) {
65+ error_log ("LaunchDarkly unable to open socket " );
6566 return ;
6667 }
6768 $ payload = json_encode ($ this ->_queue );
@@ -79,6 +80,7 @@ private function createSocket() {
7980 $ protocol = $ this ->_ssl ? "ssl " : "tcp " ;
8081
8182 try {
83+
8284 $ socket = @pfsockopen ($ protocol . ":// " . $ this ->_host , $ this ->_port , $ errno , $ errstr , $ this ->_timeout );
8385
8486 if ($ errno != 0 ) {
@@ -87,8 +89,8 @@ private function createSocket() {
8789 }
8890
8991 return $ socket ;
90-
9192 } catch (Exception $ e ) {
93+ error_log ("LaunchDarkly caught $ e " );
9294 $ this ->socket_failed = true ;
9395 return false ;
9496 }
@@ -99,7 +101,7 @@ private function createBody($content) {
99101 $ req .= "POST /api/events/bulk HTTP/1.1 \r\n" ;
100102 $ req .= "Host: " . $ this ->_host . "\r\n" ;
101103 $ req .= "Content-Type: application/json \r\n" ;
102- $ req .= "Authorization: api_key " . base64_encode ( $ this ->_apiKey ) . "\r\n" ;
104+ $ req .= "Authorization: api_key " . $ this ->_apiKey . "\r\n" ;
103105 $ req .= "User-Agent: PHPClient/ " . LDClient::VERSION . "\r\n" ;
104106 $ req .= "Accept: application/json \r\n" ;
105107 $ req .= "Content-length: " . strlen ($ content ) . "\r\n" ;
@@ -112,13 +114,12 @@ private function makeRequest($socket, $req, $retry = true) {
112114 $ bytes_written = 0 ;
113115 $ bytes_total = strlen ($ req );
114116 $ closed = false ;
115- # Write the request
117+
116118 while (!$ closed && $ bytes_written < $ bytes_total ) {
117119 try {
118- # Since we're try catch'ing prevent PHP logs.
119120 $ written = @fwrite ($ socket , substr ($ req , $ bytes_written ));
120121 } catch (Exception $ e ) {
121- // $this->handleError($e->getCode(), $e->getMessage() );
122+ error_log ( " LaunchDarkly caught $ e " );
122123 $ closed = true ;
123124 }
124125 if (!isset ($ written ) || !$ written ) {
@@ -127,25 +128,17 @@ private function makeRequest($socket, $req, $retry = true) {
127128 $ bytes_written += $ written ;
128129 }
129130 }
130- # If the socket has been closed, attempt to retry a single time.
131+
131132 if ($ closed ) {
132133 fclose ($ socket );
133134 if ($ retry ) {
135+ error_log ("LaunchDarkly retrying send " );
134136 $ socket = $ this ->createSocket ();
135137 if ($ socket ) return $ this ->makeRequest ($ socket , $ req , false );
136138 }
137139 return false ;
138140 }
139- /*
140- $success = true;
141- if ($this->debug()) {
142- $res = $this->parseResponse(fread($socket, 2048));
143- if ($res["status"] != "200") {
144- $this->handleError($res["status"], $res["message"]);
145- $success = false;
146- }
147- }
148- */
141+
149142 return true ;
150143 }
151144
0 commit comments