function __construct($app = 'default') { $this->logger = new Logger($app); $logging_path = Config::get('log.' . $app); if (Config::get('app.debug', false) == true) { $mode = Logger::DEBUG; } else { $mode = Logger::ERROR; } $this->logger->pushHandler(new StreamHandler($logging_path, $mode)); }
function sendMessage($queue, $data, $delay = 0) { $data['randomize'] = md5(rand(0, 1000000000) . rand(0, 1000000000) . rand(0, 1000000000)); $score = date("U") + $delay; Redis::zadd('cinnamon-queue-' . $queue, $score, json_encode($data)); if (Config::get('queue.auto_run', false) && defined('__APP__')) { $base_path = __APP__; if (!file_exists($base_path . "/commands/subscribe.php")) { $base_path = __APP__ . "/vendor/cinnamonlab/queue"; } $ip = $_SERVER['SERVER_ADDR']; $process = Redis::get('cinnamon-process-' . $ip); if ($process != null) { if ($process > date('U') - 600) { Redis::publish('cinnamon-process', $queue); return $this; } ob_start(); system("ps ax|grep commands/subscribe.php| grep -v grep"); $process = trim(ob_get_clean()); if (strlen($process) > 0) { Redis::set('cinnamon-process-' . $ip, date('U')); Redis::expire('cinnamon-process-' . $ip, 1200); Redis::publish('cinnamon-process', $queue); return $this; } else { Redis::del('cinnamon-process-' . $ip); } $process = null; } $cmd = "nohup " . Config::get('queue.php_path', '/usr/bin/php') . " " . $base_path . "/commands/subscribe.php {$ip} > /dev/null &"; exec($cmd); Redis::publish('cinnamon-process', $queue); } return $this; }
/** * Get the fully qualified path for a compiled view. * * @param string $view * @return string */ public static function compiled($path) { return Config::get('blade.storage') . '/' . md5($path); }
<?php use Framework\Queue\QueueProcessor; use Framework\Config; use Framework\Queue\Driver\Driver; use Framework\Queue\Driver\RedisDriver; use Framework\Exception\FrameworkException; use Framework\Input; use Framework\Route; define('__APP__', __DIR__ . "/.."); require __APP__ . "/vendor/autoload.php"; $rs = Config::get('driver', new RedisDriver()); if (!$rs instanceof Driver) { throw FrameworkException::internalError('Queue Driver Not Set'); } QueueProcessor::getInstance()->setDriver($rs)->setAsReceiver(); for ($i = 0; $i < 10; $i++) { $message = $rs->receiveMessage('route'); if (!$message) { exit; } Input::bind($message); Route::reset(); Route::setSkipMain(); include __APP__ . "/route.php"; }
function __construct($template) { $this->path = Config::get('blade.template') . "/" . preg_replace("/\\./", "/", $template) . ".php"; parent::__construct(); }
/** * */ static function emptyImage() { $output = new Imagick(); $output->setFormat("gif"); $output->newImage(Config::get('image.default.width'), Config::get('image.default.height'), new ImagickPixel(Config::get('image.default.bg_color'))); return $output->getimagesblob(); }
public static function getInstance() { if (self::$myself == null) { self::$myself = new Redis(Config::get('redis.servers')); } return self::$myself; }
function hello() { return (new Response())->setContent(Config::get('app.greeting') . Input::get('name', 'guest'))->setContentType('text/plain')->setCode(200); }
private function handleError(FrameworkException $e) { if ($this->error_response == null) { if (Config::has('app.error_response')) { $this->error_response = Config::get('app.error_response'); } else { if (Config::get('app.debug', true)) { $this->error_response = new ErrorDisplayResponse(); } else { $this->error_response = new ErrorResponse(); } } } $this->error_response->set($e)->display(); return true; }