@@ -97,7 +97,7 @@ protected function getConnection($uniq=null, $servers=null)
9797 $ start = microtime (true );
9898 $ elapsed = 0 ;
9999
100- if (is_null ($ servers )){
100+ if (is_null ($ servers )) {
101101 $ servers = $ this ->servers ;
102102 }
103103
@@ -108,11 +108,10 @@ protected function getConnection($uniq=null, $servers=null)
108108 */
109109 $ tried_servers = array ();
110110
111- while ($ conn === null && count ($ servers )){
112-
113- if (count ($ servers ) === 1 ){
111+ while ($ conn === null && count ($ servers )) {
112+ if (count ($ servers ) === 1 ) {
114113 $ key = key ($ servers );
115- } elseif ($ uniq === null ){
114+ } elseif ($ uniq === null ) {
116115 $ key = array_rand ($ servers );
117116 } else {
118117 $ key = ord (substr (md5 ($ uniq ), -1 )) % count ($ servers );
@@ -122,25 +121,14 @@ protected function getConnection($uniq=null, $servers=null)
122121
123122 $ tried_servers [] = $ server ;
124123
125- if (empty ($ this ->conn [$ server ])){
126-
124+ if (empty ($ this ->conn [$ server ])) {
127125 $ conn = null ;
128126
129127 $ start = microtime (true );
130- try {
128+ try {
131129 $ conn = new Net_Gearman_Connection ($ server , $ this ->timeout );
132- } catch (Net_Gearman_Exception $ e ) {
130+ } catch (Net_Gearman_Exception $ e ) {
133131 $ conn = null ;
134- Logger::log ("gearman_worker_error_log " , array (
135- "level " => "warning " ,
136- "event " => "client_connect " ,
137- "server " => $ server ,
138- "timeout " => $ this ->timeout ,
139- "elapsed " => microtime (true ) - $ start ,
140- "error_message " => $ e ->getMessage (),
141- "error_file " => $ e ->getFile (),
142- "error_line " => $ e ->getLine ()
143- ), true );
144132 }
145133
146134 if (!$ conn || !$ conn ->isConnected ()) {
@@ -161,9 +149,9 @@ protected function getConnection($uniq=null, $servers=null)
161149
162150 }
163151
164- if (empty ($ conn )){
152+ if (empty ($ conn )) {
165153 $ message = "Failed to connect to a Gearman server. Attempted to connect to " .implode (", " , $ tried_servers ).". " ;
166- if (count ($ tried_servers ) != count ($ try_servers )){
154+ if (count ($ tried_servers ) != count ($ try_servers )) {
167155 $ message .= " Not all servers were tried. Full server list is " .implode (", " , $ try_servers ).". " ;
168156 }
169157 throw new Net_Gearman_Exception ($ message );
@@ -230,7 +218,7 @@ protected function submitTask(Net_Gearman_Task $task)
230218
231219 // if we don't have a scalar
232220 // json encode the data
233- if (!is_scalar ($ task ->arg )){
221+ if (!is_scalar ($ task ->arg )) {
234222 $ arg = @json_encode ($ task ->arg );
235223 } else {
236224 $ arg = $ task ->arg ;
@@ -242,7 +230,7 @@ protected function submitTask(Net_Gearman_Task $task)
242230 'arg ' => $ arg
243231 );
244232
245- if (!empty ($ task ->servers )){
233+ if (!empty ($ task ->servers )) {
246234 $ servers = $ task ->servers ;
247235 } else {
248236 $ servers = null ;
@@ -269,7 +257,7 @@ public function runSet(Net_Gearman_Set $set, $timeout = null)
269257 $ taskKeys = array_keys ($ set ->tasks );
270258 $ t = 0 ;
271259
272- if ($ timeout !== null ){
260+ if ($ timeout !== null ) {
273261 $ socket_timeout = min (10 , (int )$ timeout );
274262 } else {
275263 $ socket_timeout = 10 ;
@@ -312,14 +300,14 @@ public function runSet(Net_Gearman_Set $set, $timeout = null)
312300 $ write = null ;
313301 $ except = null ;
314302 $ read_cons = array ();
315- foreach ($ this ->conn as $ conn ){
303+ foreach ($ this ->conn as $ conn ) {
316304 $ read_conns [] = $ conn ->socket ;
317305 }
318306 @socket_select ($ read_conns , $ write , $ except , $ socket_timeout );
319307 foreach ($ this ->conn as $ conn ) {
320308 $ err = socket_last_error ($ conn ->socket );
321309 // Error 11 is EAGAIN and is normal in non-blocking mode
322- if ($ err && $ err != 11 ){
310+ if ($ err && $ err != 11 ) {
323311 $ msg = socket_strerror ($ err );
324312 socket_getpeername ($ conn ->socket , $ remote_address , $ remote_port );
325313 socket_getsockname ($ conn ->socket , $ local_address , $ local_port );
@@ -395,7 +383,7 @@ public function disconnect()
395383 }
396384
397385 foreach ($ this ->conn as $ conn ) {
398- if (is_callable (array ($ conn , "close " ))){
386+ if (is_callable (array ($ conn , "close " ))) {
399387 $ conn ->close ();
400388 }
401389 }
@@ -426,7 +414,7 @@ public static function getInstance($servers, $timeout = 1000) {
426414
427415 $ key = md5 (json_encode ($ servers ));
428416
429- if (!isset ($ instances [$ key ])){
417+ if (!isset ($ instances [$ key ])) {
430418 $ instances [$ key ] = new Net_Gearman_Client ($ servers , $ timeout );
431419 }
432420
0 commit comments