时间:2021-07-01 10:21:17 帮助过:2人阅读
[2014-10-21 18:47:44] production.ERROR: exception 'Predis\Connection\ConnectionException' with message 'Error while reading line from the server [tcp://127.0.0.1:6379]' in /home/nginx/mono/vendor/predis/predis/lib/Predis/Connection/AbstractConnection.php:141
但是从redis-cli访问redis-server是ok的,在phpunit中单独测试redis也没问题。但是在Route中直接使用有问题。
Route::get('/test', function(){
Cache::put('name', 'Taylor', 60); //报错!
$name = Cache::get('name');
echo $name;
});
谁能解释下问题在哪?
补充:刷新多次/test,会有几次正常。
我使用了laravel 4 framework开发,想把cache server从memcache切换到redis,在config/cache.php的driver设置为redis。但是调用cache::get()报错,报错信息如:
[2014-10-21 18:47:44] production.ERROR: exception 'Predis\Connection\ConnectionException' with message 'Error while reading line from the server [tcp://127.0.0.1:6379]' in /home/nginx/mono/vendor/predis/predis/lib/Predis/Connection/AbstractConnection.php:141
但是从redis-cli访问redis-server是ok的,在phpunit中单独测试redis也没问题。但是在Route中直接使用有问题。
Route::get('/test', function(){
Cache::put('name', 'Taylor', 60); //报错!
$name = Cache::get('name');
echo $name;
});
谁能解释下问题在哪?
补充:刷新多次/test,会有几次正常。
Predis的StreamConnection Class
/**
* Initializes a TCP stream resource.
*
* @param ConnectionParametersInterface $parameters Parameters used to initialize the connection.
* @return resource
*/
protected function tcpStreamInitializer(ConnectionParametersInterface $parameters)
{
$uri = "tcp://{$parameters->host}:{$parameters->port}";
$flags = STREAM_CLIENT_CONNECT;
if (isset($parameters->async_connect) && $parameters->async_connect) {
$flags |= STREAM_CLIENT_ASYNC_CONNECT;
}
if (isset($parameters->persistent) && $parameters->persistent) {
$flags |= STREAM_CLIENT_PERSISTENT;
$uri .= strpos($path = $parameters->path, '/') === 0 ? $path : "/$path";
}
$resource = @stream_socket_client($uri, $errno, $errstr, $parameters->timeout, $flags);
if (!$resource) {
$this->onConnectionError(trim($errstr), $errno);
}
//问题在这里,需要给读取流设置超时时间,否则就在读取流数据时连接报错,
//可以直接设置read_write_timeout为0,以此解决问题。
if (isset($parameters->read_write_timeout)) {
$rwtimeout = $parameters->read_write_timeout;
$rwtimeout = $rwtimeout > 0 ? $rwtimeout : -1;
$timeoutSeconds = floor($rwtimeout);
$timeoutUSeconds = ($rwtimeout - $timeoutSeconds) * 1000000;
stream_set_timeout($resource, $timeoutSeconds, $timeoutUSeconds);
}
if (isset($parameters->tcp_nodelay) && function_exists('socket_import_stream')) {
$socket = socket_import_stream($resource);
socket_set_option($socket, SOL_TCP, TCP_NODELAY, (int) $parameters->tcp_nodelay);
}
return $resource;
}
production.ERROR
config 中是否有 production
文件夹?里面是否有 cache.php 文件?那样的话会覆盖外面的配置。