예제 #1
0
 public function errorHandler($errno, $errstr, $errfile, $errline, array $errcontext)
 {
     $error = compact("errno", "errstr", "errfile", "errline");
     if ((int) $errno & (E_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR | E_WARNING)) {
         $this->trigger("error", $error);
     }
     log::error(var_export($error, 1));
 }
예제 #2
0
 protected function onInStreamClose()
 {
     $this->inStream->off("close", [$this, "onInStreamClose"]);
     // If stream is closed, but no STOP event received
     if ($this->isProcOpen()) {
         $pid = $this->getPID();
         $sig = $this->getTermSig();
         $error = "Unexpected child death ({$pid}): " . ($sig ? "signaled {$sig}" : "unknown reason");
         log::error($error);
         $this->trigger("error", $error);
         $this->trigger("stop");
     }
 }
예제 #3
0
 public static function send($fifo, $message)
 {
     $message = serialize($message);
     $messageLen = hex2bin(str_pad(dechex(strlen($message)), self::MESSAGE_LEN_FIELD_LENGTH_BYTES * 2, "0", STR_PAD_LEFT));
     $writeStream = fopen($fifo, "c+");
     if (!$writeStream) {
         throw new \Exception("Could not open fifo {$fifo} for writing: " . var_export(error_get_last(), 1));
     }
     if (!fwrite($writeStream, $messageLen . $message)) {
         log::warning("Could not write to fifo {$fifo}");
         throw new \Exception("Could not write to fifo {$fifo}");
     } else {
         log::debug("Written message to {$fifo}");
     }
     fclose($writeStream);
 }
예제 #4
0
파일: Mx1.php 프로젝트: a13k5and3r/Stream
 /**
  * Send message to all pipes in directory, optionally using StreamSet
  *
  * @param string $fifoPath    Path to directory with pipes
  * @param mixed  $message     Message should be castable to string
  * @param mixed $useStreamSet If \Phasty\Stream\StreamSet use it for streams \
  *                            If false no need using streams \
  *                            If null use default StreamSet instance
  */
 public static function send($fifoPath, $message, $useStreamSet = false)
 {
     $fifos = glob("{$fifoPath}/*");
     $message = (string) $message;
     log::debug("Mx1 send to " . count($fifos) . " fifos");
     foreach ($fifos as $fifo) {
         if (!isset(self::$streams[$fifo])) {
             self::$streams[$fifo] = new \Phasty\Stream\Reader\NamedPipe($fifo);
             if ($useStreamSet !== false) {
                 if (is_null($useStreamSet)) {
                     self::$streams[$fifo]->setStreamSet(\Phasty\Stream\StreamSet::instance());
                 } else {
                     self::$streams[$fifo]->setStreamSet($useStreamSet);
                 }
             }
             self::$streams[$fifo]->on("close", function () use($fifo) {
                 unset(self::$streams[$fifo]);
             });
         }
         self::$streams[$fifo]->write($message);
     }
 }
예제 #5
0
파일: Task.php 프로젝트: a13k5and3r/Tman
 protected function log($msg)
 {
     $error = false;
     if ($msg instanceof \Exception) {
         $msg = sprintf("Exception (%d) %s in %s:%d", $msg->getCode(), $msg->getMessage(), $msg->getFile(), $msg->getLine());
         $error = true;
     }
     if (!$this->canLog) {
         echo "{$msg}\n";
         return;
     }
     if ($this->verbose) {
         echo "{$msg}\n";
     }
     $error ? log::error($msg) : log::info($msg);
 }
예제 #6
0
 public function onData(Event $event)
 {
     $this->messages .= $data = $event->getData();
     $i = 0;
     while (false !== ($msg = $this->extractMessage())) {
         $i++;
         $eventObject = unserialize($msg);
         foreach ($this->listeners as $listener) {
             $listener->trigger($eventObject);
         }
     }
     if ($this->messages && !$i) {
         $msg = $this->messages;
         if (strlen($msg) < 100) {
             $msg = "0x" . bin2hex($msg);
         }
         log::error("Got broken message:\n{$msg}");
         log::error("last data: " . var_export($data, 1));
     }
 }
예제 #7
0
파일: async.php 프로젝트: phasty/process
#!/usr/bin/php
<?php 
$dir = dirname(dirname(__FILE__));
if (is_file("{$dir}/vendor/autoload.php")) {
    $autoloadFile = "{$dir}/vendor/autoload.php";
} else {
    $autoloadFile = dirname(dirname($dir)) . "/autoload.php";
}
include_once $autoloadFile;
if ($argc < 4) {
    echo "Wrong argument count";
    exit(1);
}
$requiredFiles = unserialize(base64_decode($argv[1]));
foreach ($requiredFiles as $requiredFile) {
    require $requiredFile;
}
$calleeEntity = unserialize(base64_decode($argv[2]));
$calleeMethod = unserialize(base64_decode($argv[3]));
$arguments = $argc > 4 ? unserialize(base64_decode($argv[4])) : [];
if (is_string($calleeEntity)) {
    $calleeEntity = new $calleeEntity();
}
$child = new \Phasty\Process\Child($calleeEntity);
try {
    call_user_func_array([$calleeEntity, $calleeMethod], $arguments);
} catch (\Exception $e) {
    $child->trigger("error", $e->getMessage());
    \Phasty\Log\File::error($e->getMessage());
}
예제 #8
0
 public function write($data)
 {
     log::debug("Writing data to {$this->fifoFile}");
     parent::write($data);
 }
예제 #9
0
파일: Task.php 프로젝트: phasty/tman
 protected function logByType($msg, $type)
 {
     if (!$this->canLog) {
         echo "{$msg}\n";
         return;
     }
     if ($this->verbose) {
         echo "{$msg}\n";
     }
     switch ($type) {
         case 'error':
             log::error($msg);
             break;
         case 'debug':
             log::debug($msg);
             break;
         default:
             log::info($msg);
     }
 }