Beispiel #1
0
 /**
  * Returns the current process title.
  *
  * @return string
  */
 public function getProcessTitle()
 {
     if (function_exists('cli_get_process_title')) {
         return cli_get_process_title();
         //PHP >= 5.5.
     } else {
         return exec('ps -p ' . getmypid() . ' -o command| tail -1', $out);
     }
 }
Beispiel #2
0
 public function setTitle($flag = 'proxy')
 {
     $title = cli_get_process_title();
     $titles = explode(' --sw', $title, 2);
     $title = sprintf('%s --sw-%s', $titles[0], $flag);
     cli_set_process_title($title);
 }
Beispiel #3
0
<?php
echo "Process title: " . cli_get_process_title() . "\n";
?>

<?php
define("MY_CONSTANT", 1);
print_r(get_defined_constants(true));
?> 
Beispiel #4
0
 /**
  * starts the thread, all the parameters are
  * passed to the callback function
  *
  * @return $this
  * @throws \Exception
  */
 public function start()
 {
     $pid = @pcntl_fork();
     if ($pid == -1) {
         throw new \Exception($this->getError(self::COULD_NOT_FORK), self::COULD_NOT_FORK);
     }
     if ($pid) {
         // master process
         $this->pid = $pid;
     } else {
         // child process
         cli_set_process_title(cli_get_process_title() . self::CHILD_POSTFIX);
         $arguments = func_get_args();
         pcntl_signal(SIGTERM, array(__CLASS__, 'signalHandler'));
         register_shutdown_function(array(__CLASS__, 'signalHandler'));
         pcntl_signal_dispatch();
         try {
             call_user_func_array($this->runnable, $arguments);
         } catch (\Exception $exception) {
             self::log()->addError("[EXCEPTION] {$exception->getMessage()} in {$exception->getFile()}:{$exception->getLine()}");
             MPCMF_DEBUG && error_log("Stack trace:\n{$exception->getTraceAsString()}");
         }
         exit(0);
     }
     return $this;
 }
Beispiel #5
0
 /**
  * Returns a title of the current process
  * @return string
  */
 protected function getTitle()
 {
     if (is_callable('cli_get_process_title')) {
         return \cli_get_process_title();
     }
     return false;
 }
Beispiel #6
0
 /**
  * Get process title.
  *
  * @access  public
  * @return  string
  */
 public static function getTitle()
 {
     if (PHP_VERSION_ID < 50500) {
         return null;
     }
     return cli_get_process_title();
 }
Beispiel #7
0
 /**
  * Returns a title of the current process
  *
  * @return string
  */
 protected function getTitle()
 {
     return cli_get_process_title();
 }
<?php

echo "*** Testing setting the process title ***\n";
$set_title = $original_title = uniqid("title", true);
$pid = getmypid();
if (cli_set_process_title($original_title) === true) {
    echo "Successfully set title\n";
}
$ps_output = shell_exec("ps -p {$pid} -o command | tail -n 1");
if ($ps_output === null) {
    echo "ps failed\n";
    die;
}
$loaded_title = trim($ps_output);
if (strpos(strtoupper(substr(PHP_OS, 0, 13)), "BSD") !== false) {
    // Fix up title for BSD
    $set_title = "php: {$original_title} (php)";
}
if ($loaded_title == $set_title) {
    echo "Successfully verified title using ps\n";
} else {
    echo "Actually loaded from ps: {$loaded_title}\n";
}
$read_title = cli_get_process_title();
if ($read_title == $original_title) {
    echo "Successfully verified title using get\n";
} else {
    echo "Actually loaded from get: {$read_title}\n";
}