Пример #1
0
require 'config.php';
use Respect\Validation\Validator as v;
use Respect\Validation\Exceptions\NestedValidationExceptionInterface;
$app = new \Slim\App();
$container = $app->getContainer();
$pheanstalk = new \Pheanstalk\Pheanstalk($config['beanstalk_server']);
$view = new \Slim\Views\Twig('templates');
$view->addExtension(new Slim\Views\TwigExtension($container->get('router'), $container->get('request')->getUri()));
$container->register($view);
$app->get('/', function ($req, $res) {
    return $this->view->render($res, 'index.html', ['currentTube' => 'default']);
});
$app->get('/api/info', function ($req, $res) use($pheanstalk, $config) {
    $tube = $req->getParam('tube', 'default');
    try {
        $isServiceListening = $pheanstalk->getConnection()->isServiceListening();
        try {
            $job = $pheanstalk->peekBuried($tube);
            $statsJob = $pheanstalk->statsJob($job);
            $jobBuried = ['data' => $job->getData(), 'stats' => $statsJob];
        } catch (\Pheanstalk\Exception\ServerException $e) {
            $jobBuried = null;
        }
        try {
            $job = $pheanstalk->peekDelayed($tube);
            $statsJob = $pheanstalk->statsJob($job);
            $jobDelayed = ['data' => $job->getData(), 'stats' => $statsJob];
        } catch (\Pheanstalk\Exception\ServerException $e) {
            $jobDelayed = null;
        }
        try {
<?php

//start init $pheanstalk instance
require __DIR__ . '/../vendor/autoload.php';
$pheanstalk = new Pheanstalk\Pheanstalk('beanstalkd');
//end init $pheanstalk instance
if ($pheanstalk->getConnection()->isServiceListening() === false) {
    print "Error: Cannot connect to beanstalkd.";
} else {
    print "Connected to beanstalkd.<br/><br/>";
    //start add job to queue
    $job_data = "Current timestamp: " . time();
    $pheanstalk->useTube('testqueue')->put($job_data);
    //end add job to queue
    print "Job sent data => <b>{$job_data}</b>";
}