|  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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
18 + 21 = ?
Subscribe to this entry?

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

Test script:
$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
	if ($msg) {
		echo $msg->getBody() . "\n";

	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

			pcntl_wait($status, WNOHANG); //Protects against Zombie children
$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.'


Add a Patch

Pull Requests

Add a Pull Request


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 for progress.
 [2013-04-17 15:34 UTC]
closing this. When all amqp resources are created in the child only, the 
described problem does not exist.
 [2013-04-17 15:34 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: bkw
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri Sep 17 05:03:37 2021 UTC