gpt4 book ai didi

php - Windows 10 上的 Memcache PHP 扩展间歇性工作

转载 作者:行者123 更新时间:2023-12-03 01:47:54 24 4
gpt4 key购买 nike

我在 apache/php windows 10 上有 memcache 扩展(详细信息在最后)

创建了一个简单的测试:

$memcache = new Memcache;
$memcache->addServer("ext-memcached.e-memcached.xxx.net",11211);
$memcache->addServer("ext-memcached.e-memcached2.xxx.net",11211);
$memcache->addServer("ext-memcached.e-memcached3.xxx.net",11211);

$key='xxx_54921';
$settings = $memcache->get($key);
print_r ($settings);

memcache 服务器位于 AWS 上,并且运行良好(生产服务器)。此测试代码有效 - 它从内存缓存服务器检索值。但是,如果我等待几分钟并刷新,它将不会返回值。然后,如果我再次刷新,它将返回该值。

相同的代码/配置可以在另一台开发计算机上使用。

什么原因会导致这种情况?

Config:
PHP Version 5.6.34
Windows NT SPECTRE 6.2 build 9200 (Windows 8 Home Premium Edition) i586
Build Date Feb 28 2018 17:45:55
Compiler MSVC11 (Visual C++ 2012)
Architecture x86

Memcache extension:
ts x86 version from here:
https://windows.php.net/downloads/pecl/releases/memcache/3.0.8/

memcache info:
memcache support enabled
Version 3.0.8
Revision $Revision: 329835 $
Directive Local Value Master Value
memcache.allow_failover 1 1
memcache.chunk_size 32768 32768
memcache.compress_threshold 20000 20000
memcache.default_port 11211 11211
memcache.hash_function crc32 crc32
memcache.hash_strategy standard standard
memcache.lock_timeout 600 600
memcache.max_failover_attempts 20 20
memcache.protocol ascii ascii
memcache.redundancy 1 1
memcache.session_redundancy 2 2

最佳答案

memcached 服务实际上并不为您安装 PHP memcached 扩展。它仅安装用于存储缓存的 memcached 服务器。

您需要首先从 PECL 存储库下载 Windows DLL(单击蓝色的 Windows DLL 链接)。然后,您必须将 extension=php_memcache.dll 行添加到 SAPI 的正确 php.ini 文件中。另请注意,扩展 DLL 文件需要放置在 XAMPP 安装的正确路径中。

对于 Apache,只需使用以下行在文档根目录中创建一个脚本

对于 CLI SAPI,您可以使用 php.exe --ini 执行相同的操作。同样,如果 XAMPP 包修改了您的配置路径,您可能需要依赖它(因为这是一个编译时指令)。

对 php.ini 进行更改后,您需要重新启动 PHP 才能使更改生效。

您可以引用:https://pureform.wordpress.com/2008/01/10/installing-memcache-on-windows-for-php/

由于您在 Windows 上使用 PHP 7,因此可能还需要注意,从 PECL 编译的 DLL 实际上可能无法在 Windows 的 apache 下工作,因为您很可能使用带头的 SAPI。因此,请确保您下载的是正确的版本。据我所知,该版本仅编译用于 PHP 5.6 以下版本。 PHP 7 的 github 替代方案可在 https://github.com/nono303/PHP7-memcahe-dll 获取。正如评论中提到的,是在非线程安全下进行测试的。因此,您可能只能在 Windows 上的 CLI 脚本中使用此功能。

关于php - Windows 10 上的 Memcache PHP 扩展间歇性工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51525590/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com