Php worker 空闲时间 15 分钟后出现异常
Php worker Exception after idle time of 15 minutes
我已经编写了一个 php worker 来从 RabbitMQ 获取数据 queue.The php worker 运行 成功地作为连接 RabbitMQ 服务器的某些服务器上的后台作业使用 AMQP 使用数据 php extension.After 15 分钟内队列中没有数据,php 脚本抛出 AMQPException。
例外是:
AMQPException Object
(
[message:protected] => Library error: a socket error occurred
[string:Exception:private] =>
[code:protected] => 0
[file:protected] => /home/indiamart/public_html/dev-weberp-auto-dialer/merp/devworker.php
[line:protected] => 104
[trace:Exception:private] => Array
(
[0] => Array
(
[file] => /home/indiamart/public_html/dev-weberp-auto-dialer/merp/devworker.php
[line] => 104
[function] => consume
[class] => AMQPQueue
[type] => ->
[args] => Array
(
[0] => Closure Object
(
[parameter] => Array
(
[$message] => <required>
[$q] => <required>
)
)
)
)
)
[previous:Exception:private] =>
)
下面是我的工人代码:
<?php
$callback_func = function(AMQPEnvelope $message, AMQPQueue $q){
$data = json_decode($message->getBody(), true);
$getDeliveryTag = $message->getDeliveryTag();
$ack = $q->ack($getDeliveryTag);//used $getDeliveryTag
$to = isset($data["to"])?$data["to"]:"";
$subjectMail = isset($data["subject"])?$data["subject"]:"";
$mail_body_content = isset($data["body"])?"<pre>".$data["body"]."</pre>":"";
$mailfrom = isset($data["mailfrom"])?$data["mailfrom"]:"";
$cc = isset($data["cc"])?$data["cc"]:"";
$mailfromname = isset($data["mailfromname"])?$data["mailfromname"]:"";
$uniqueid = isset($data["unique_id"])?$data["unique_id"]:"";
if(!$ack){//if ack not recieved
$ack_msg = "Unique id: $uniqueid Subject : $subjectMail";
@mail("abc@example.com","History Queue Not acknowledged!",$ack_msg);
}
if($message->isRedelivery()){
$red_msg = "Unique id: $uniqueid Subject : $subjectMail";
@mail("abc@example.com","History Queue Redilivery!",$red_msg);
}
$m_headers_trail = "From:$mailfromname<$mailfrom> \n".
"Cc:$cc\n".
"MIME-Version: 1.0 \n".
"Content-type: text/html; charset=UTF-8";
$flag = @mail($to,$subjectMail,$mail_body_content,$m_headers_trail);
$flag_message = $flag ? "success unique id: $uniqueid Subject :$subjectMail" : "mail failed";
@mail("abc@example.com","History Mailer Result",$flag_message);
};
$host = "127.0.0.1";
$vhost = "/";
$port = 5672;
$login = "admin";
$password = "admin";
CHANNEL :
try{
@mail("abc@example.com","History Queue worker Start!","Worker
started!");
$cnn = new AMQPConnection(array("host" => $host,"vhost" => $vhost,"port"
=> $port,"login" => $login,"password" => $password));
$cnn->connect();
if(!$cnn){
@mail("abc@example.com","History Queue Connection
Error!","Connection not established!");
}
$ch = new AMQPChannel($cnn);
$queue = new AMQPQueue($ch);
$queue->setName('STS_UPDATE_MAIL');
$queue->setFlags(AMQP_NOPARAM);
$queue->consume($callback_func);
$ch->close();
$cnn->close();
}catch(Exception $e){
if ($ch->isConnected()) {
$ch->close();
@mail("abc@example.com","History Queue Closing
Connection!","Closed!");
}
if ($cnn->isConnected()) {
$cnn->close();
@mail("abc@example.com","History Queue Closing
Connection!","Closed!");
}
goto CHANNEL;
}
?>
这是图书馆的问题。我比 golang
转移了工人
我已经编写了一个 php worker 来从 RabbitMQ 获取数据 queue.The php worker 运行 成功地作为连接 RabbitMQ 服务器的某些服务器上的后台作业使用 AMQP 使用数据 php extension.After 15 分钟内队列中没有数据,php 脚本抛出 AMQPException。 例外是:
AMQPException Object (
[message:protected] => Library error: a socket error occurred
[string:Exception:private] =>
[code:protected] => 0
[file:protected] => /home/indiamart/public_html/dev-weberp-auto-dialer/merp/devworker.php
[line:protected] => 104
[trace:Exception:private] => Array
(
[0] => Array
(
[file] => /home/indiamart/public_html/dev-weberp-auto-dialer/merp/devworker.php
[line] => 104
[function] => consume
[class] => AMQPQueue
[type] => ->
[args] => Array
(
[0] => Closure Object
(
[parameter] => Array
(
[$message] => <required>
[$q] => <required>
)
)
)
)
)
[previous:Exception:private] =>
)
下面是我的工人代码:
<?php
$callback_func = function(AMQPEnvelope $message, AMQPQueue $q){
$data = json_decode($message->getBody(), true);
$getDeliveryTag = $message->getDeliveryTag();
$ack = $q->ack($getDeliveryTag);//used $getDeliveryTag
$to = isset($data["to"])?$data["to"]:"";
$subjectMail = isset($data["subject"])?$data["subject"]:"";
$mail_body_content = isset($data["body"])?"<pre>".$data["body"]."</pre>":"";
$mailfrom = isset($data["mailfrom"])?$data["mailfrom"]:"";
$cc = isset($data["cc"])?$data["cc"]:"";
$mailfromname = isset($data["mailfromname"])?$data["mailfromname"]:"";
$uniqueid = isset($data["unique_id"])?$data["unique_id"]:"";
if(!$ack){//if ack not recieved
$ack_msg = "Unique id: $uniqueid Subject : $subjectMail";
@mail("abc@example.com","History Queue Not acknowledged!",$ack_msg);
}
if($message->isRedelivery()){
$red_msg = "Unique id: $uniqueid Subject : $subjectMail";
@mail("abc@example.com","History Queue Redilivery!",$red_msg);
}
$m_headers_trail = "From:$mailfromname<$mailfrom> \n".
"Cc:$cc\n".
"MIME-Version: 1.0 \n".
"Content-type: text/html; charset=UTF-8";
$flag = @mail($to,$subjectMail,$mail_body_content,$m_headers_trail);
$flag_message = $flag ? "success unique id: $uniqueid Subject :$subjectMail" : "mail failed";
@mail("abc@example.com","History Mailer Result",$flag_message);
};
$host = "127.0.0.1";
$vhost = "/";
$port = 5672;
$login = "admin";
$password = "admin";
CHANNEL :
try{
@mail("abc@example.com","History Queue worker Start!","Worker
started!");
$cnn = new AMQPConnection(array("host" => $host,"vhost" => $vhost,"port"
=> $port,"login" => $login,"password" => $password));
$cnn->connect();
if(!$cnn){
@mail("abc@example.com","History Queue Connection
Error!","Connection not established!");
}
$ch = new AMQPChannel($cnn);
$queue = new AMQPQueue($ch);
$queue->setName('STS_UPDATE_MAIL');
$queue->setFlags(AMQP_NOPARAM);
$queue->consume($callback_func);
$ch->close();
$cnn->close();
}catch(Exception $e){
if ($ch->isConnected()) {
$ch->close();
@mail("abc@example.com","History Queue Closing
Connection!","Closed!");
}
if ($cnn->isConnected()) {
$cnn->close();
@mail("abc@example.com","History Queue Closing
Connection!","Closed!");
}
goto CHANNEL;
}
?>
这是图书馆的问题。我比 golang
转移了工人