Exemplo n.º 1
0
 /**
  * @param string        $socketAddress
  * @param resource|null $socketContext
  *
  * @throws Exception\BindOrListenException
  *
  * @return resource
  */
 public static function createServerSocket($socketAddress, $socketContext = null)
 {
     try {
         return self::doCreateServerSocket($socketAddress, $socketContext);
     } catch (Exception\BindOrListenException $e) {
         if (($socketFile = IdentificationHelper::getSocketFile($socketAddress)) !== null) {
             try {
                 fclose(self::createClientSocket($socketAddress, 1, $socketContext));
                 // Really in use
                 throw $e;
             } catch (Exception\ConnectException $e2) {
                 // False positive due to a residual socket file
                 unlink($socketFile);
                 return self::doCreateServerSocket($socketAddress, $socketContext);
             }
         } else {
             throw $e;
         }
     }
 }
Exemplo n.º 2
0
 /** {@inheritdoc} */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->parseCommandLine($input, $alsoDisable, $includeRemote, $factory, $signal);
     $registry = $this->getRegistry();
     foreach ($registry->getSharedWorkerNames() as $name) {
         $address = $registry->getSharedWorkerSocketAddress($name);
         $local = IdentificationHelper::isLocalAddress($address);
         if (!$includeRemote & !$local) {
             $output->writeln('Skipped remote worker <comment>' . $name . '</comment>.');
             continue;
         }
         $wFactory = $registry->getSharedWorkerFactoryName($name);
         if ($factory !== null && $wFactory != $factory) {
             $output->writeln('Skipped ' . ($local ? 'local' : 'remote') . ' worker <comment>' . $name . '</comment> from factory <comment>' . $wFactory . '</comment>.');
             continue;
         }
         $factory = $registry->getSharedWorkerFactory($name);
         $profile = $factory->getBootstrapProfile();
         if ($alsoDisable & $local) {
             $this->disableWorker($output, $profile, $name, $wFactory);
         }
         $this->stopWorker($output, $profile, $name, $local, $signal, $wFactory);
     }
 }
Exemplo n.º 3
0
 /**
  * @throws Exception\RuntimeException
  *
  * @return int|null
  */
 public function getProcessId()
 {
     if ($this->processId === false) {
         $this->processId = IdentificationHelper::getListeningProcessId($this->socketAddress);
     }
     return $this->processId;
 }
Exemplo n.º 4
0
 /**
  * @param string            $name
  * @param string            $wFactory
  * @param int|null          $pid
  * @param string            $socketAddress
  * @param WorkerStatus|null $status
  *
  * @return array
  */
 private function makeRow($name, $wFactory, $pid, $socketAddress, WorkerStatus $status = null)
 {
     $flags = $this->getFlags($name, $pid, IdentificationHelper::isLocalAddress($socketAddress), $status);
     return [implode($flags), $this->makeColoredName($name, $flags), $wFactory, $pid !== null ? strval($pid) : '<fg=blue>unknown</fg=blue>', IdentificationHelper::isNetworkExposedAddress($socketAddress) ? IdentificationHelper::stripScheme($socketAddress) : '<fg=blue>local-only</fg=blue>', $status !== null ? $status->getTextStatus() : '<fg=blue>no data</fg=blue>'];
 }
Exemplo n.º 5
0
 /**
  * @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;
 }
Exemplo n.º 6
0
 /** {@inheritdoc} */
 public function clear($cacheDir)
 {
     foreach ($this->sharedWorkers as $sharedWorker) {
         $factory = $this->getFactory($sharedWorker[0]);
         if (IdentificationHelper::isLocalAddress($sharedWorker[1])) {
             $factory->stopSharedWorker($sharedWorker[1]);
         }
     }
 }