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

Publish event missing #64

Closed
Deisss opened this issue Apr 13, 2012 · 5 comments
Closed

Publish event missing #64

Deisss opened this issue Apr 13, 2012 · 5 comments

Comments

@Deisss
Copy link

Deisss commented Apr 13, 2012

On PubSubContext.php :

Please add the following command :

After class start :
const PUBLISH = 'publish';

Somewhere :
/**
* Publish an event to the specified channel
* @param mixed $arg,... One or more channel names.
/
public function publish(/
arguments */){
$this->writeCommand(self::PUBLISH, func_get_args());
}

Based on code showed for subscribe & co. Tested & work ;)

@nrk
Copy link
Contributor

nrk commented Apr 13, 2012

Are you sure it works for you? The problem is that you can't send PUBLISH to a channel using the same connection being used to receive messages because Redis internally marks that connection in a special state, and if you try do do that Redis will reply with -ERR only (P)SUBSCRIBE / (P)UNSUBSCRIBE / QUIT allowed in this context.

@Deisss
Copy link
Author

Deisss commented Apr 13, 2012

I've no idea, i did this stuff because i'm using only publish from PHP.

I use publish from PHP to send an event recieved by Node.JS and Node.JS publish a real time modifcation to all client (socket.io).

So I don't use subscribe from PHP, but from Node.JS, there is so 2 connection, and in this way it works great !

So maybe you should create a specific cas which refuse to use both with same connection...

@nrk
Copy link
Contributor

nrk commented Apr 13, 2012

If you don't subscribe to any channel from PHP then you don't need the Predis\PubSub\PubSubContext class since it implements an abstraction for a pubsub consumer loop (and this is why that class implements only the commands allowed in a pub/sub context). Just use PUBLISH with the plain client instance:

$client = new Predis\Client();
$client->publish('my:channel', 'message payload');

@nrk nrk closed this as completed Apr 13, 2012
@jmoz
Copy link

jmoz commented Dec 12, 2012

FYI It might be worth putting that last point somewhere near the pubsub subscribe docs as I've just spent a while trying to figure out the same thing.

@nrk
Copy link
Contributor

nrk commented Dec 12, 2012

@jmoz sure, will do that soon since we are starting with writing a descriptive documentation of the whole library.

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

No branches or pull requests

3 participants