Pheanstalk queueng list reserve PHP

970 Views Asked by At

Hi All i am having trouble on my pheanstalk sorry this is my first time of using this. My project involves a one save of 5000 entries the php when i work on gets 502 because of the traffic request.So my solution to these is to use a pheanstalk on the process here is my code below which is okay. I have installed the beanstalk on the server.

    require("vendor/autoload.php");
use Pheanstalk\Pheanstalk;
$pheanstalk = new Pheanstalk('127.0.0.1');   

#producer
$put = $pheanstalk->useTube("ashimatube".date("His"))
->put(json_encode(array("test"=>date("Yhs"))));

#worker
$job = $pheanstalk->watch("ashimatube".date("His"))
->ignore("default")->reserve();
1

There are 1 best solutions below

0
On

Beanstalk

Beanstalk used in Facebook developed by Philotic, Inc to improves the response time for the Causes on the Facebook application (with over 10 million users). Beanstalk decreased the average response time for the most common pages to a tiny fraction of the original, significantly improving the user experience.

Here is the sample for Codeigniter

  1. Download Pheastalk from here.

Pheastalk is a PHP client for beanstalkd queue.

  1. Add Pheanstalk folder inside application/libraries.

  2. Create pheanstalk.php under application/config.

  3. Add the following code.

    <?php
    
      if (!defined('BASEPATH'))
        exit('No direct script access allowed');
    
       $config['ip'] = '192.168.0.2'; // Example IP, Enter your IP
       $config['port'] = 11300;
    
  4. Create Pheanstalk.php (P is in caps) under application/libraries.

  5. Add the following code.

     if (!defined('BASEPATH'))
       exit('No direct script access allowed');
    
     /** Pheanstalk root directory */
     if (!defined('PHEANSTALK_ROOT')) 
     {
          define('PHEANSTALK_ROOT', dirname(__FILE__) . '/');
          require(PHEANSTALK_ROOT . 'pheanstalk/pheanstalk_init.php');
     }
    
     class Pheanstalk extends Pheanstalk_Pheanstalk 
     {
    
        public function __construct($params) 
        {
            parent::__construct($params['ip'], $params['port']);
        }
     } 
    
  6. Create a controller like this.

     Class Test extends CI_Controller 
     {
    
      public function index() 
      {
        $this->load->library('pheanstalk');
        var_dump($this->pheanstalk->listTubes());
        $this->pheanstalk->useTube('testtube')->put("job payload goes here\n");
    
        $job = $this->pheanstalk
                ->watch('testtube')
                ->ignore('default')
                ->reserve();
    
        echo $job->getData();
    
        $this->pheanstalk->delete($job);
    } }
    

Just Try this way.