Unable to get Beanstalkd Queue to work for PHP

眉间皱痕 提交于 2019-12-02 04:44:06

SOLUTION FOUND:

After some more research, I have managed to get it to work! A decent amount was missing to get to that point. The process was the following:

  1. Execute sudo apt-get install beanstalkd in the linux terminal to install beanstalkd.
  2. Execute sudo apt install composer to install composer, which is the program recommended to be used to install pheanstalk.
  3. Create a composer.json file that will let composer know what library to download and what version of said library. For instance:

    {
      "require": {
        "pda\pheanstalk": "2.1.1"
      }
    }
    
  4. Execute composer install in the linux terminal. This has to be done in the same folder as the composer.json file.

  5. Include the necessary code that will initiate the Pheanstalk class, and use it as documented. And that is it! Sample code would be as follows:

    <?php
    
    require_once('vendor/autoload.php');//require the autoload file provided by
                                        //composer
    
    //Initiate an instance of the Pheanstalk class
    $pheanstalk = new Pheanstalk_Pheanstalk('127.0.0.1');
    
    //adding a job to queue/tube testtube:
    $pheanstalk->useTube('testtube')->put('message');
    
    //obtaining the job by a worker:
    $job = $pheanstalk->watch('testtube')->ignore('default')->reserve();
    
    echo $job->getData;//outputting the message
    
    $pheanstalk->delete($job);//deleting the job from the queue.
    
    ?>
    
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!