来自 PHP 的 Redis 连接缓慢 [英] Redis connection slow from PHP

查看:47
本文介绍了来自 PHP 的 Redis 连接缓慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始在我的应用程序中使用 Redis,但出于某种原因,从 PHP 到 Redis 服务器的初始连接几乎需要 1 秒.使用 Predis 时,直到第一次 get() 调用才会出现延迟问题,如果我尝试手动连接,延迟会发生在通过 fsockopen() 的初始连接上.

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().

我已阅读 redis 延迟文档,但似乎没有任何信息与我的案例相关.运行 redis-cli --latency 似乎只会产生一团乱码.我想我的问题是解决此问题的最佳方法是什么?任何帮助将不胜感激.

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 客户端实例化:

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

以下是一些相关信息:

  • PHP 5.4.7
  • XAMPP
  • Windows 7 64 位
  • 16GB 内存
  • redis 服务器本地运行在 6379 端口

推荐答案

在 windows 上总是使用 127.0.0.1 而不是 localhost.

On windows always use 127.0.0.1 instead of localhost.

在最近版本的 Windows 解析名称 localhost 是在 DNS 本身内处理的(它是帮助合并 IPv6 的功能")并且这个 dns 查询总是需要 1 秒.

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.

这篇关于来自 PHP 的 Redis 连接缓慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆