Laravel4Predis accessing redis returns Errorwhilereadinglinefromtheserver

Source: Internet
Author: User
I used laravel4framework for development. I want to switch the cacheserver from memcache to redis, and set the driver in configcache. php to redis. However, an error is returned when cache: get () is called. The error message is {code ...} but access to redis-server from redis-cli is OK... I used laravel 4 framework for Development. I want to switch the cache server from memcache to redis, in config/cache. set the driver of php to redis. However, an error is reported when cache: get () is called. The error message is as follows:

[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

However, access to redis-server from redis-cli is OK, and it is okay to test redis separately in phpunit. However, there is a problem in using Route directly.

Route: get ('/test', function () {Cache: put ('name', 'taylor', 60); // error! $ Name = Cache: get ('name'); echo $ name ;});

Who can explain the problem?

Supplement: refresh multiple times/test, several times normal.

Reply content:

I used laravel 4 framework for Development. I want to switch the cache server from memcache to redis, and set the driver in config/cache. php to redis. However, an error is reported when cache: get () is called. The error message is as follows:

[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

However, access to redis-server from redis-cli is OK, and it is okay to test redis separately in phpunit. However, there is a problem in using Route directly.

Route: get ('/test', function () {Cache: put ('name', 'taylor', 60); // error! $ Name = Cache: get ('name'); echo $ name ;});

Who can explain the problem?

Supplement: refresh multiple times/test, several times normal.

StreamConnection Class of Predis

/*** 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);} // here, you need to set a timeout value for the read stream, otherwise, an error is reported when the stream data is read. // you can directly set read_write_timeout to 0 to solve the problem. 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

ConfigproductionFolder? Is there a cache. php file? In this case, the external configurations will be overwritten.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.