没有不值得去解决的问题,也没有不值得去学习的技术!

Install Memcached on Windows 10 64-bit and the Memcache Extension for PHP 7.0.22

Check phpinfo; memcache is now present

1. I previously wrote a blog post about PHP 5.6.27: https://www.shuijingwanwq.com/2017/09/11/1892/ , and this time it is for PHP 7.0.22, as shown in Figure 1

I previously wrote a blog post about PHP 5.6.27: https://www.shuijingwanwq.com/2017/09/11/1892/ , and this time it is for PHP 7.0.22
Figure 1

2. To uninstall memcached, you can use the following command: , as shown in Figure 2
schtasks /delete /tn memcached

Uninstall memcached
Figure 2

3. Delete the directory: C:\memcached-1.4.5, as shown in Figure 3

Delete the directory: C:\memcached-1.4.5
Figure 3

4. Open the URL: https://github.com/nono303/memcached/tree/master/cygwin/x64 , and download: cygevent-2-0-5.dll, cygwin1.dll, memcached-1.5.1.exe, as shown in Figure 4

Open the URL: https://github.com/nono303/memcached/tree/master/cygwin/x64 , and download: cygevent-2-0-5.dll, cygwin1.dll, memcached-1.5.1.exe
Figure 4

5. After downloading successfully, copy the files to: C:\memcached-1.5.1, as shown in Figure 5

After downloading successfully, copy the files to: C:\memcached-1.5.1
Figure 5

6. Run Windows PowerShell as an administrator, as shown in Figure 6

Run Windows PowerShell as an administrator
Figure 6

7. Execute the following command to add memcached to the Task Scheduler: , as shown in Figure 7
schtasks /create /sc onstart /tn memcached /tr “‘C:\memcached-1.5.1\memcached-1.5.1.exe’ -m 512”

Execute the following command to add memcached to the Task Scheduler
Figure 7

8. Open the URL: https://github.com/nono303/PHP7-memcache-dll , and select vc14, as shown in Figure 8

Open the URL: https://github.com/nono303/PHP7-memcache-dll , and select vc14
Figure 8

9. Check phpinfo; the compiler is MSVC14 and it is thread-safe, as shown in Figure 9

Check phpinfo; the compiler is MSVC14 and it is thread-safe
Figure 9

10. Open the URL: https://github.com/nono303/PHP7-memcache-dll/tree/master/vc14/x64/ts , and download: php-7.0.x_memcache.dll, as shown in Figure 10

Open the URL: https://github.com/nono303/PHP7-memcache-dll/tree/master/vc14/x64/ts , and download: php-7.0.x_memcache.dll
Figure 10

11. Copy php-7.0.x_memcache.dll to: C:\php-7.0.22\ext\php_memcache.dll, as shown in Figure 11

Copy php-7.0.x_memcache.dll to: C:\php-7.0.22\ext\php_memcache.dll
Figure 11

12. Add the following line in C:\php-7.0.22\php.ini to enable the memcache extension, as shown in Figure 12
extension=php_memcache.dll

Add the following line in C:\php-7.0.22\php.ini to enable the memcache extension
Figure 12

13. Check phpinfo; memcache is now present, as shown in Figure 13

Check phpinfo; memcache is now present
Figure 13

14. Create a new test program: memcached.php, as shown in Figure 14

Create a new test program: memcached.php
Figure 14
PHP
<?php
 
$memcache = new Memcache;
$memcache->connect('localhost', 11211) or die ("Could not connect");
 
$version = $memcache->getVersion();
echo "Server's version: ".$version."<br/>\n";
 
$tmp_object = new stdClass;
$tmp_object->str_attr = 'test';
$tmp_object->int_attr = 123;
 
$memcache->set('key', $tmp_object, false, 10) or die ("Failed to save data at the server");
echo "Store data in the cache (data will expire in 10 seconds)<br/>\n";
 
$get_result = $memcache->get('key');
echo "Data from the cache:<br/>\n";
 
var_dump($get_result);
 
?>

15. After restarting the machine, running the test program throws an error: Notice: Memcache::connect(): Server localhost (tcp 11211, udp 0) failed with: , as shown in Figure 15

After restarting the machine, running the test program throws an error: Notice: Memcache::connect(): Server localhost (tcp 11211, udp 0) failed with:
Figure 15

16. Open the Task Scheduler, edit the trigger for memcached, and change it from “At startup” to “At log on”, as shown in Figure 16

Open the Task Scheduler, edit the trigger for memcached, and change it from "At startup" to "At log on"
Figure 16

17. At this point, the trigger for memcached is now set to: “At log on of any user”, as shown in Figure 17

At this point, the trigger for memcached is now set to: "At log on of any user"
Figure 17

18. After restarting the machine, the C:\memcached-1.5.1\memcached-1.5.1.exe command-line window appears, indicating that the scheduled task executed successfully, as shown in Figure 18

After restarting the machine, the C:\memcached-1.5.1\memcached-1.5.1.exe command-line window appears, indicating that the scheduled task executed successfully
Figure 18

19. Run the test program; it works normally, as shown in Figure 19

Run the test program; it works normally
Figure 19

20. I want the command-line window not to appear when the system starts, so I change the user or group, as shown in Figure 20

I want the command-line window not to appear when the system starts, so I change the user or group
Figure 20

21. In the “Select User or Group” window that pops up, we select Advanced – Find Now – select SYSTEM, and click OK, as shown in Figure 21

In the "Select User or Group" window that pops up, we select Advanced - Find Now - select SYSTEM, and click OK
Figure 21

22. “When running the task, use the following user account:” is now set to: SYSTEM, as shown in Figure 22

"When running the task, use the following user account:" is now set to: SYSTEM
Figure 22

23. After restarting the machine, the C:\memcached-1.5.1\memcached-1.5.1.exe command-line window is not displayed, and running the test program works normally, as shown in Figure 23

After restarting the machine, the C:\memcached-1.5.1\memcached-1.5.1.exe command-line window is not displayed, and running the test program works normally
Figure 23

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系