Skip to content

Commit e3340ed

Browse files
committed
remove logging
1 parent cc4fba6 commit e3340ed

File tree

3 files changed

+62
-175
lines changed

3 files changed

+62
-175
lines changed

Net/Gearman/Client.php

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Net/Gearman/Connection.php

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class Net_Gearman_Connection
108108
public $socket;
109109

110110
public function __construct($host=null, $timeout=250) {
111-
if ($host){
111+
if ($host) {
112112
$this->connect($host, $timeout);
113113
}
114114
}
@@ -175,7 +175,7 @@ public function connect($host, $timeout = 250)
175175
* trying.
176176
*/
177177
$socket_connected = false;
178-
do{
178+
do {
179179
socket_clear_error($this->socket);
180180
$socket_connected = @socket_connect($this->socket, $host, $port);
181181
$err = @socket_last_error($this->socket);
@@ -191,16 +191,15 @@ public function connect($host, $timeout = 250)
191191
$socket_connected = $socket_connected && $err === 0;
192192

193193

194-
if ($socket_connected){
195-
194+
if ($socket_connected) {
196195
socket_set_nonblock($this->socket);
197196

198197
socket_set_option($this->socket, SOL_SOCKET, SO_KEEPALIVE, 1);
199198

200199
/**
201200
* set the real send/receive timeouts here now that we are connected
202201
*/
203-
if ($timeout >= 1000){
202+
if ($timeout >= 1000) {
204203
$ts_seconds = $timeout / 1000;
205204
$tv_sec = floor($ts_seconds);
206205
$tv_usec = ($ts_seconds - $tv_sec) * 1000000;
@@ -213,13 +212,8 @@ public function connect($host, $timeout = 250)
213212

214213
// socket_set_option($this->socket, SOL_TCP, SO_DEBUG, 1); // Debug
215214

216-
StatsD::timing("application.gearman.connect_time_per_server.".GetConfig::get("dealnews.location")."_to_".str_replace(".", "_", $host), $elapsed);
217-
218215
} else {
219216

220-
StatsD::timing("application.gearman.connect_time_per_server_failure.".GetConfig::get("dealnews.location")."_to_".str_replace(".", "_", $host), $elapsed);
221-
StatsD::increment("application.gearman.connect_failed.".GetConfig::get("dealnews.location")."_to_".str_replace(".", "_", $host), 1);
222-
223217
$errno = @socket_last_error($this->socket);
224218
$errstr = @socket_strerror($errno);
225219

@@ -238,11 +232,11 @@ public function connect($host, $timeout = 250)
238232

239233
}
240234

241-
public function addWaitingTask($task){
235+
public function addWaitingTask($task) {
242236
$this->waiting[] = $task;
243237
}
244238

245-
public function getWaitingTask(){
239+
public function getWaitingTask() {
246240
return array_shift($this->waiting);
247241
}
248242

@@ -276,8 +270,6 @@ public function send($command, array $params = array())
276270

277271
$d = implode("\x00", $data);
278272

279-
// use for debug: Logger::log("gearman_worker_error_log", getmypid().":send:$command");
280-
281273
$cmd = "\0REQ" . pack("NN",
282274
$this->commands[$command][0],
283275
$this->stringLength($d)) . $d;
@@ -373,8 +365,6 @@ public function read()
373365
throw new Net_Gearman_Exception("({$return['err_code']}): {$return['err_text']}");
374366
}
375367

376-
// use for debug: Logger::log("gearman_worker_error_log", getmypid().":read:".$this->magic[$resp['type']][0]);
377-
378368
return array('function' => $this->magic[$resp['type']][0],
379369
'type' => $resp['type'],
380370
'data' => $return);
@@ -392,7 +382,7 @@ public function blockingRead($timeout = 1000)
392382
{
393383
$cmds = array();
394384

395-
if ($timeout >= 1000){
385+
if ($timeout >= 1000) {
396386
$ts_seconds = $timeout / 1000;
397387
$tv_sec = floor($ts_seconds);
398388
$tv_usec = ($ts_seconds - $tv_sec) * 1000000;
@@ -408,19 +398,19 @@ public function blockingRead($timeout = 1000)
408398
$start = microtime(true);
409399
$success = @socket_select($read, $write, $except, $tv_sec, $tv_usec);
410400
$et = (microtime(true) - $start) * 1000;
411-
if ($success === false){
401+
if ($success === false) {
412402
$errno = @socket_last_error($this->socket);
413-
if ($errno != 0){
403+
if ($errno != 0) {
414404
throw new Net_Gearman_Exception("Socket error: ($errno) ".socket_strerror($errno));
415405
}
416406
}
417407

418-
if ($success === 0){
408+
if ($success === 0) {
419409
$errno = @socket_last_error($this->socket);
420410
throw new Net_Gearman_Exception("Socket timeout ($et): ($errno) ".socket_strerror($errno));
421411
}
422412

423-
if (count($read)){
413+
if (count($read)) {
424414
foreach ($read as $s) {
425415
$cmds[] = $this->read();
426416
}

0 commit comments

Comments
 (0)