Using a queue system for handling jobs. We have a cron run once every morning at 1am and it publishes all of our required API calls. We have another consumer cron that runs every five minutes that addresses the requests in the queue.
We are in a shared environment and scripts called via cron are terminated after 15 minutes. Therefore to protect ourselves we gracefully terminate our script after 9 minutes.
Nearly all of our API calls are running with the exception of (2), which we are trying to figure out why. When we run them manually via the same script they work perfectly. Strange. Only fail when run via cron with all of the other requests.
In any case the nightly logs show the following Fatal Error occurring multiple times. Maybe this is the culprit. Unable to determine what is causing this. If I manually kill the AMQP connections I get a different error so I know $ch and $conn are not being overridden somewhere in one of the API calls.
Fatal error: Call to a member function basic_get() on resource in /........../consume_requests.php on line 116
Below is our initialization of phpamqplib. Any help would be appreciated.
require '/vendors/php-amqplib/autoload.php';
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;
try {
$queue = 'my_queue';
$url = parse_url(URL);
$conn = new AMQPStreamConnection(HOST, 5555, USER, PASS, PATH, 1));
$ch = $conn->channel();
$ch->queue_declare($queue, false, true, false, false);
$ch->exchange_declare(EXCHANGE, 'direct', true, true, false);
$ch->queue_bind($queue, EXCHANGE,$queue);
} catch(Exception $e) {
echo $e->getMessage();
}
while($message_receipt = $ch->basic_get($queue)) { //line 116