subscribe Segment fault #36

Closed
jonnywang opened this Issue Aug 5, 2011 · 12 comments

7 participants

@jonnywang

code test.php
///
#!/usr/bin/php -q
<?php
$redis = new Redis();
$redis->connect('127.0.0.1',6379);

function channel($redis, $channel, $msg) {
switch($channel) {
case 'world':
echo $msg . "\n";
break;
case 'city':
break;
case 'union':
break;
case 'firend':
break;
}
}

$redis->subscribe(array('world', 'city', 'union', 'firend'), 'channel');

?>
///
usage like ./test.php

the code like these under termial throw a Segment fault,is that a bug?

@gregr401

Also running into a seg fault while performing subscribes as above. php5.3.3, redis 2.4rc5, don't recall which rev of phpredis tho.

@nicolasff

I can't reproduce this, but I fixed a bug a few weeks ago that addressed a very similar problem. Could you please try the latest phpredis master?

Thanks.

@jonnywang

Thanks,The latest version is ok! I want to konw how to make the connect isn't timeout,if i set a max timeout seconds to pconnect?

@KnightE

You can set timeout=0 meaning unlimited

@jonnywang

You tested it? I tested it,it also produce a error Fatal error: Uncaught exception 'RedisException' with message 'read error on connection' ,Although I changed the redis.conf timeout=0 or use code like

#!/usr/bin/php -q
<?php
$redis = new Redis();
$redis->pconnect('127.0.0.1',6379, 0);

function channel($redis, $channel, $msg) {
switch($channel) {
case 'world':
echo $msg . "\n";
break;
case 'city':
break;
case 'union':
break;
case 'firend':
break;
}
}

$redis->subscribe(array('world', 'city', 'union', 'firend'), 'channel');

?>

@jonnywang jonnywang closed this Aug 10, 2011
@nicolasff
@nicolasff

Also, make sure there is no client timeout on the Redis side (have a look in redis.conf).

@jonnywang

I tested it like this
1. change redis.conf
timeout 0
2.use code
#!/usr/bin/php -q
<?php
$redis = new Redis();
// $redis->connect('127.0.0.1',6379) also reproduce read error on connection
$redis->pconnect('127.0.0.1',6379);

function channel($redis, $channel, $msg) {
switch($channel) {
case 'world':
echo $msg . "\n";
break;
case 'city':
break;
case 'union':
break;
case 'firend':
break;
}
}

$redis->subscribe(array('world', 'city', 'union', 'firend'), 'channel');

?>

Could you tell me detail how to do ?

@timaelliott

PHP's default_socket_timeout is the problem here -- It defaults to 60 and will kill connections after that period. You can't set it to 0 either (everything fails immediately). Unsure of a solution at this point.

@meanfreepath

RE default_socket_timeout, adding the line:
ini_set('default_socket_timeout', -1);
seemed to solve the problem for me (Centos5, PHP 5.3.8)

@jonnywang

Thanks,ini_set('default_socket_timeout', -1) is ok

@Seldaek

The ini_set trick works, but it would be great if phpredis would do it by default on the socket it opens using http://docs.php.net/manual/en/function.stream-set-timeout.php - not sure if it's feasible in C, but I'd hope so.

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