Пример #1
0
 function index()
 {
     $beanstalk = new \Pheanstalk\Pheanstalk('127.0.0.1');
     $beanstalk->useTube("testtube");
     /*for($i=1;$i<=100;$i++) {
           $id = $beanstalk->putInTube("testtube","job payload goes heres\n".$i);
           echo $id.PHP_EOL;
       }*/
     $job = $beanstalk->watch("testtube")->ignore('default')->reserve();
     echo $job->getData();
     //$beanstalk->delete($job);
 }
Пример #2
0
 private function _createPheanstalk()
 {
     $pheanstalk = new \Pheanstalk\Pheanstalk(self::SERVER_HOST);
     $tube = preg_replace('#[^a-z]#', '', strtolower(__CLASS__));
     $pheanstalk->useTube($tube)->watch($tube)->ignore('default');
     try {
         while ($pheanstalk->delete($pheanstalk->peekDelayed())) {
         }
     } catch (\Pheanstalk\Exception\ServerException $e) {
     }
     try {
         while ($pheanstalk->delete($pheanstalk->peekReady())) {
         }
     } catch (\Pheanstalk\Exception\ServerException $e) {
     }
     return $pheanstalk;
 }
Пример #3
0
<?php

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
error_reporting(error_reporting() & ~E_USER_DEPRECATED);
require_once __DIR__ . '/../vendor/autoload.php';
$app = new Silex\Application();
$app->register(new Igorw\Silex\ConfigServiceProvider(__DIR__ . "/../app/config/parameters.yml"));
$app->get('/', function () use($app) {
    return $app->redirect('https://www.devboard.xyz/');
});
$app->post('/github/', function (Request $request) use($app) {
    $webHookSecret = $app['parameters']['github_webhook_secret'];
    $beanstalkIp = $app['parameters']['beanstalk'];
    $eventFactory = new \DevBoard\Notify\EventFactory();
    $securityChecker = new \DevBoard\Notify\EventSecurityChecker($webHookSecret);
    $event = $eventFactory->create($request);
    if (!$securityChecker->check($event)) {
        return new Response('Wrong sig!', 400);
    }
    $pheanstalk = new \Pheanstalk\Pheanstalk($beanstalkIp);
    $pheanstalk->useTube('github-tube')->put(json_encode($event));
    $pheanstalk->useTube('testdata-tube')->put(json_encode($event));
    return new Response('Received!', 200);
});
$app->run();
<?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>";
}