pheanstalk和beantalk功能 [英] pheanstalk and beanstalk functions

查看:106
本文介绍了pheanstalk和beantalk功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码摘自pheanstalk的示例,该示例已实现并正常运行(从pheanstalk的github页面获得: https://github.com/pda/pheanstalk ):

The following code is a snipet taken from an example of pheanstalk being implemented and working properly (obtained from pheanstalk's github page: https://github.com/pda/pheanstalk):

<?php

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

// ------------ producer (queues jobs):

$pheanstalk
  ->useTube('testtube')
  ->put("job payload goes here\n");

// ------------ worker (performs jobs):

$job = $pheanstalk
  ->watch('testtube')
  ->ignore('default')
  ->reserve();

echo $job->getData();
$pheanstalk->delete($job);

// ------------ check server availability

$pheanstalk->getConnection()->isServiceListening(); // true or false

问题:

我不理解的是以下部分:

What I don't understand are the following parts:

  1. 我假设producer代码中的换行符空格对执行没有任何影响,因此此行是等效的:

  1. I am assuming that the newline spaces in the producer code don't make any difference in the execution, so this line would be equivalent:

$pheanstalk->useTube('testtube')->put("job payload goes here\n");

正确吗?如果是这样,那么这些特定的函数调用必须按该顺序进行,还是可以按任何顺序进行?我以前对php中的函数和类的理解是,您可以直接从其类类型的对象中调用一个函数:$object->classFunction(),但是以上代码是一种有效的php技术,您可以在其中同时调用所有这些函数,或者它是某种东西pheanstalk特别吗?

correct? If that is true, then do those specific function calls have to be in that order, or can they be in any order? My previous understanding of functions and classes in php was that you would directly call a function from an object of it's class type: $object->classFunction(), however is the above code a valid php technique where you can call all those functions simultaneously or is it something special to pheanstalk?

  1. ignore('default')代码在做什么?

$pheanstalk->getConnection()->isServiceListening();代码在做什么?

推荐答案

  1. 您是正确的,空格是无关紧要的.您所看到的称为方法链接

$pheanstalk->useTube('testtube')->put("job payload goes here\n");

等效于:

$temp = $pheanstalk->useTube('testtube');
$temp->put("job payload goes here\n");

因此,它首先调用useTube()来指定应将有效载荷放入哪个管中,然后将有效载荷放入其中.取决于执行操作的方法返回调用它们的Pheanstalk对象的事实,因此它也是以下简称:

So first it calls useTube() to specify which tube the payload should be put into, then it puts the payload into that. It's depending on the fact that methods that perform actions return the Pheanstalk object they were called on, so it's also short for:

$pheanstalk->useTube('testtube');
$pheanstalk->put("job payload goes here\n");

  1. ignore(tubename)从监视列表中删除该管.默认情况下会监视default管,因此将其禁用,仅等待testtube管中的消息.

  1. ignore(tubename) removes that tube from the watchlist. The default tube is watched by default, so this disables that and just waits for messages in the testtube tube.

它确实在执行上面的注释:检查服务器是否可用.您可以在生产者代码中使用它来报告错误,然后再尝试将其发送到未监听的beantalk服务器.

It's doing exactly what the comment above it says: Checking that the server is available. You could use this in your producer code to report an error before trying to send to a beanstalk server that's not listening.

这篇关于pheanstalk和beantalk功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆