コード例 #1
0
 public function Job_Lookup_Word()
 {
     $word = $this->job_details->word;
     $this->status = 'working';
     $this->Report();
     try {
         $url = 'http://www.dictionaryapi.com/api/v1/references/collegiate/xml/' . urlencode($word) . '?key=' . DICTIONARY_API_KEY;
         $contents = @file_get_contents($url);
         /*
          * I really don't know how to manipulate very complex XML easily in PHP,
          * so please ignore the hideous hacks that you are about to see.
          */
         $xml = new SimpleXMLElement($contents);
         $results = $xml->xpath('/entry_list/entry[1]//dt');
         $return = '';
         foreach ($results as $node) {
             /* @var $node SimpleXMLElement */
             $string = $node->asXML();
             // Please ignore the developer behind the curtain
             $string = str_replace('<dt>:', '', $string);
             $string = str_replace(':</dt>', '', $string);
             $def = trim(strip_tags($string));
             // Return the longest definition
             if (strlen($def) > strlen($return)) {
                 $return = $def;
             }
         }
     } catch (Exception $ex) {
         $def = "{$word} failed: " . $ex->getMessage();
     }
     // Okay, you can start paying attention again now.
     $json = json_encode(array('word' => $word, 'def' => $def));
     $this->last_word = $word;
     $this->last_def = $def;
     echo "\n {$word}: {$return} \n";
     $this->redis->lpush('word.defs', $json);
     $this->redis->ltrim('word.defs', 0, 20);
     $this->beanstalk->delete($this->job);
     // Wait 2 seconds so we don't overload the API
     usleep(2000000);
 }
コード例 #2
0
 /**
  * Delete the job from the queue.
  *
  * @return void
  */
 public function delete()
 {
     parent::delete();
     $this->pheanstalk->delete($this->job);
 }
コード例 #3
0
ファイル: index.php プロジェクト: lucasRolff/webpagetest
/**
* See if we can talk to beanstalkd
* 
*/
function CheckBeanstalkd()
{
    global $settings;
    $ret = false;
    require_once './lib/beanstalkd/pheanstalk_init.php';
    $pheanstalk = new Pheanstalk_Pheanstalk($settings['beanstalkd']);
    if ($pheanstalk->getConnection()->isServiceListening()) {
        $id = $pheanstalk->putInTube('wpt.installtest', "test");
        $jobStats = $pheanstalk->statsJob($id);
        $tubeStats = $pheanstalk->statsTube('wpt.installtest');
        $job = $pheanstalk->reserveFromTube('wpt.installtest', 0);
        if ($job !== false && $job->getData() == 'test') {
            $ret = true;
        }
        $pheanstalk->delete($job);
    }
    return $ret;
}
コード例 #4
0
ファイル: beanstalkd.php プロジェクト: hosopy/fuel-jobqueue
 /**
  * Delete the job from the queue.
  *
  * @return void
  */
 public function delete()
 {
     $this->pheanstalk->delete($this->job);
 }
コード例 #5
0
 /**
  * Delete a job
  */
 public function deleteAction()
 {
     $server = $this->_getParam("server");
     $jobId = $this->_getParam("id");
     try {
         // Connect to the server
         $messageQueue = new Pheanstalk_Pheanstalk($server);
         $job = $messageQueue->peek($jobId);
         $messageQueue->delete($job);
         $response = "";
     } catch (Exception $e) {
         $this->getResponse()->setHttpResponseCode(500);
         $response = $e->getMessage();
     }
     // Send Json response
     $this->jsonHelper->sendJson($response);
     $this->jsonHelper->getResponse()->sendResponse();
 }
コード例 #6
0
ファイル: Beanstalk.php プロジェクト: itillawarra/cmfive
 public function clearQueue($queue)
 {
     while ($job = $this->queue->reserve(0)) {
         $this->queue->delete($job);
     }
 }
コード例 #7
0
ファイル: PheanstalkTubeQueue.php プロジェクト: yiqing95/bbq
 public function finalizeJob(JobInterface $job)
 {
     $this->pheanstalk->delete($job->getPheanstalkJob());
 }
コード例 #8
0
ファイル: harupload.php プロジェクト: risyasin/webpagetest
function ProcessTests($crawl)
{
    global $beanstalkd;
    $tube = 'har.' . $crawl;
    $pheanstalk = new Pheanstalk_Pheanstalk($beanstalkd);
    do {
        $got_test = true;
        try {
            $job = $pheanstalk->reserveFromTube($tube, 0);
            if ($job !== false) {
                $id = $job->getData();
                if (ProcessTest($id)) {
                    $pheanstalk->delete($job);
                } else {
                    $pheanstalk->release($job);
                }
            } else {
                $got_test = false;
            }
        } catch (Exception $e) {
            if ($e->getMessage() == 'Server reported NOT_FOUND') {
                $got_test = false;
            } else {
                unset($pheanstalk);
                sleep(1);
                $pheanstalk = new Pheanstalk_Pheanstalk($beanstalkd);
            }
        }
    } while ($got_test);
    unset($pheanstalk);
}