/** * @param string $socketAddress * @param WorkerBootstrapProfile $bootstrapProfile * @param int|null $timeout * * @throws Exception\ConnectException * * @return ChannelInterface */ private static function connect($socketAddress, WorkerBootstrapProfile $bootstrapProfile, $timeout = null) { $socket = SocketFactory::createClientSocket($socketAddress, $timeout); $connection = Source::fromStream($socket, true, null, false); return $bootstrapProfile->getChannelFactory()->createChannel(new BufferedSource($connection), $connection); }
/** * @param string $socketAddress * * @throws Exception\BindOrListenException * @throws Exception\RuntimeException * * @return resource */ private static function startListening($socketAddress) { $lock = Lock::acquire(); if (self::$killSwitchPath !== null) { $kswitch = new KillSwitch(self::$killSwitchPath); if ($kswitch->getGlobal() || $kswitch->hasAddress($socketAddress)) { throw new Exception\RuntimeException('This worker has been prevented from starting using the kill switch'); } } $socketFile = IdentificationHelper::getSocketFile($socketAddress); if ($socketFile !== null) { $socketDir = dirname($socketFile); if (!is_dir($socketDir)) { mkdir($socketDir, 0777, true); } } $server = SocketFactory::createServerSocket($socketAddress, self::$socketContext); $lock->release(); self::$socket = $server; self::$listening = true; self::$toDelete = $socketFile; return $server; }