8000 add ability for child to send message to parent before child exit · notion/forkdaemon-php@a40020c · GitHub
[go: up one dir, main page]

Skip to content

Commit a40020c

Browse files
author
Lindsay Snider
committed
add ability for child to send message to parent before child exit
1 parent b5c1710 commit a40020c

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

fork_daemon.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,13 @@ class fork_daemon
185185
*/
186186
protected $exit_request_status = false;
187187

188+
/**
189+
* In the child process, stores the socket to get results back to the parent
190+
*
191+
* @var null
192+
*/
193+
protected $child_socket_to_parent = null;
194+
188195
/**************** SERVER CONTROLS ****************/
189196
/**
190197
* Upper limit on the number of children started.
@@ -1506,12 +1513,21 @@ public function has_result($bucket = self::DEFAULT_BUCKET)
15061513
/**
15071514
* Run signals sent to the process
15081515
*/
1509-
static public function dispatch_signals()
1516+
public static function dispatch_signals()
15101517
{
15111518
// Run signal handlers
15121519
pcntl_signal_dispatch();
15131520
}
15141521

1522+
/**
1523+
* Send a message from the child to the parent
1524+
* @param $result
1525+
*/
1526+
public function child_send_result_to_parent($result)
1527+
{
1528+
self::socket_send($this->child_socket_to_parent, $result);
1529+
}
1530+
15151531
/**
15161532
* Checks if any changed child sockets are in the bucket.
15171533
*
@@ -1764,6 +1780,9 @@ protected function fork_work_unit($work_unit, $identifier = '', $bucket = self::
17641780
$this->forked_children = null;
17651781
$this->results = null;
17661782

1783+
// save the socket from child to parent to support $this->child_send_result_to_parent()
1784+
$this->child_socket_to_parent = $socket_parent;
1785+
17671786
// set child properties
17681787
$this->child_bucket = $bucket;
17691788

0 commit comments

Comments
 (0)
0