Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It keeps loading just like infinite loop #159

Closed
developerside opened this issue Jan 16, 2017 · 3 comments
Closed

It keeps loading just like infinite loop #159

developerside opened this issue Jan 16, 2017 · 3 comments

Comments

@developerside
Copy link

i have added the pheanstalk and beanstalk to the server my problem is that when i have directly run the php code it always have infinite loop here is my worker
worker.php

<?php 
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require("vendor/autoload.php");
function p($s){
	echo "<pre>";
	print_r($s);
	echo "</pre>";
}
use Pheanstalk\Pheanstalk;
$pheanstalk = new Pheanstalk('127.0.0.1');  //initiating an object
$watches = $pheanstalk->watch("ashimatube103613");
  if ($pheanstalk->getConnection()->isServiceListening() == true) {  
	  p($job = $pheanstalk->reserve());  
	 while($job = $pheanstalk->reserve()) {
		$getdata = $job->getData();		
		p($getdata);
		echo 'test this is ';	
		$pheanstalk->delete($job);
	} 
  }
  $start  = $pheanstalk->getConnection()->isServiceListening(); // true or false
	echo $start."listening";
	try {
		# $job = $pheanstalk->reserve();
		# p($job->getData());
	  echo 'here test';
	} catch (Exception $e) {
		echo "Error sending message - {$e->getMessage()} \n";
	}

what did i done wrong?

here is my producer code producer.php

<?php 
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
#echo phpinfo();
require("vendor/autoload.php");

function p($s){
	echo "<pre>";
	print_r($s);
	echo "</pre>";
}
use Pheanstalk\Pheanstalk;

 
$pheanstalk = new Pheanstalk('127.0.0.1');  //initiating an object

$args = array(
	"date" => "2017-1-17",
	"id"=>array("7","8","39","4")
);

#producer
$put = $pheanstalk->useTube("ashimatube103613")->put(json_encode(array($args)));
exit();
@123Daoxyz
Copy link

your worker.php keeping looping ?

@videni
Copy link

videni commented Apr 28, 2018

@developerside , hi, I think you can simple try this

 do {
            $job = $this->pheanstalk
            ->watch('forecast')
            ->ignore('default')
            ->reserve();

            var_dump($job->getData());

            $this->pheanstalk->delete($job);
        } while (true);

when there is no more job , the reserve will hold.

@SamMousa
Copy link
Collaborator

Closing this since a solution was proposed and no feedback on that solution was provided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants