Redis connection slow from PHP

眉间皱痕 提交于 2020-01-05 15:05:52

问题


I just started using Redis in my application, but for some reason the initial connection to the Redis server from PHP takes almost exactly 1 second. When using Predis, the latency issue doesn't occur until the first get() call, and if I try connecting manually the latency occurs on the initial connection via fsockopen().

I've read the redis latency documentation, but none of the information seemed relevant to my case. Running redis-cli --latency just seemed to product a garbled mess. I guess my question is what's the best way to troubleshoot this? Any help would be much appreciated.

Predis Client instantiation:

$redis = new Predis\Client(array(
    'host'     => 'localhost',
    'port'     => 6379
));

Here's some relevant info:

  • PHP 5.4.7
  • XAMPP
  • Windows 7 64-bit
  • 16GB ram
  • The redis server is running locally on port 6379

回答1:


On windows always use 127.0.0.1 instead of localhost.

In recent versions of windows resolution of name localhost is handled within DNS itself (it is a "feature" to help incorporate IPv6) and this dns query always take 1 sec.



来源:https://stackoverflow.com/questions/14076403/redis-connection-slow-from-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!