php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62099 It doesn't compatible with pcntl
Submitted: 2012-05-21 20:18 UTC Modified: 2013-04-17 15:34 UTC
From: 66ton99 at gmail dot com Assigned: bkw (profile)
Status: Closed Package: amqp (PECL)
PHP Version: 5.3.10 OS: Lubuntu 12.04
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: 66ton99 at gmail dot com
New email:
PHP Version: OS:

 

 [2012-05-21 20:18 UTC] 66ton99 at gmail dot com
Description:
------------
It crashes on next iteration after created fork process by pcntl_fork()

Test script:
---------------
<?php
$connection = new AMQPConnection();$connection->connect();
$channel = new AMQPChannel($connection);
$q = new AMQPQueue($channel);$q->setName('queue.hello');$q->declare();
while (true) {
	$msg = $q->get(AMQP_NOPARAM); // It will crush on second iteration
	sleep(2);
	if ($msg) {
		echo $msg->getBody() . "\n";
		$q->ack($msg->getDeliveryTag());
	}

	switch ($pid = pcntl_fork()) {
		case -1: // Fail
			die("Cant create fork process");

		case 0:
			echo "New process \n";
			exit; // The end of the forked process

		default:
			pcntl_wait($status, WNOHANG); //Protects against Zombie children
			break;
	}
}
$connection->disconnect(); // disconnect

Expected result:
----------------
It some times freeze and lost Channel but not the connection.
But usually throw PHP Fatal error:  Uncaught exception 'AMQPQueueException' with 
message 'Unknown server error occurred.'


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-05-21 20:20 UTC] 66ton99 at gmail dot com
Changed PHP version
 [2012-05-21 20:20 UTC] 66ton99 at gmail dot com
-PHP Version: 5.3.13 +PHP Version: 5.3.10
 [2012-11-14 02:08 UTC] bkw at codingforce dot com
Since the underlying rabbitmq-c library is not thread safe, you should not reuse 
an global resource in the forked processes, since all children will share one 
physical connection, similar to sharing a socket without calling accept on it.

For your use case, just create a new connection with the fork block, and you 
should be fine.
 [2012-11-14 02:11 UTC] bkw at codingforce dot com
sorry, chrome's autocorrection got in the way: I meant to write:

just create a new connection scoped withIN the fork block (case 0), and you 
should be fine.
 [2012-11-14 14:21 UTC] bkw at codingforce dot com
actually what I wrote is (no longer?) true. I'm looking into this.
Watch https://github.com/pdezwart/php-amqp/issues/28 for progress.
 [2013-04-17 15:34 UTC] bkw@php.net
closing this. When all amqp resources are created in the child only, the 
described problem does not exist.
 [2013-04-17 15:34 UTC] bkw@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: bkw
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Tue Aug 03 13:01:23 2021 UTC