


Install memcache module for PHP extension under linux_PHP tutorial
Installation environment
RHEL 4
Php 5.2.6
Required software
libevent-1.4.6-stable.tar.gz (http://monkey.org/~provos/libevent/)
memcache-2.2.3.tgz (http://pecl.php.net/package/memcache)
memcached-1.2.6.tar.gz (http://www.danga.com/memcached/)
Installation configuration
1. Install libevent
# tar zxf libevent-1.4.6-stable.tar.gz
# cd libevent-1.4.6-stable
# ./configure --prefix=/usr/local/servers/libevent
# make && make install
2. Install memcached
# tar zxvf memcached-1.2.6.tar.gz
# cd memcached-1.2.6
# ./configure --prefix=/usr/local/servers/memcached --with-libevent=/usr/local/servers/libevent
# make && make install
3. Run memcached
# /usr/local/servers/memcached -d -m 128 -l localhost -p 11211 -u root
-d runs memcached in daemon mode;
-m sets the memory size that memcached can use, in M;
-l sets the monitoring IP address. If it is the local machine, this parameter usually does not need to be set;
-p sets the listening port, the default is 11211, so this parameter does not need to be set;
-u specifies user;
If you encounter problems when running memcached, the error message is as follows:
/usr/local/servers/memcached/bin/memcached: error while loading shared libraries: libevent-1.4.so.2: cannot open shared object file: No such file or directory
Then run LD_DUBUG=libs to know the loading path of the library when memcached is started. The details are as follows:
# LD_DEBUG=libs /usr/local/servers/memcached/bin/memcached -v
10929: find library=libevent-1.4.so.2 [0]; searching
10929: search cache=/etc/ld.so.cache
10929: Search path=/lib/tls/i686/sse2:/lib/tls/i686:/lib/tls/sse2:/lib/tls:/lib/i686/sse2:/lib/i686:/lib/sse2: /lib:/usr/lib/tls/i686/sse2:/usr/lib/tls/i686:/usr/lib/tls/sse2:/usr/lib/tls:/usr/lib/i686/sse2:/usr /lib/i686:/usr/lib/sse2:/usr/lib (system search path)
10929: trying file=/lib/tls/i686/sse2/libevent-1.4.so.2
10929: trying file=/lib/tls/i686/libevent-1.4.so.2
10929: trying file=/lib/tls/sse2/libevent-1.4.so.2
10929: trying file=/lib/tls/libevent-1.4.so.2
10929: trying file=/lib/i686/sse2/libevent-1.4.so.2
10929: trying file=/lib/i686/libevent-1.4.so.2
10929: trying file=/lib/sse2/libevent-1.4.so.2
10929: trying file=/lib/libevent-1.4.so.2
10929: trying file=/usr/lib/tls/i686/sse2/libevent-1.4.so.2
10929: trying file=/usr/lib/tls/i686/libevent-1.4.so.2
10929: trying file=/usr/lib/tls/sse2/libevent-1.4.so.2
10929: trying file=/usr/lib/tls/libevent-1.4.so.2
10929: trying file=/usr/lib/i686/sse2/libevent-1.4.so.2
10929: trying file=/usr/lib/i686/libevent-1.4.so.2
10929: trying file=/usr/lib/sse2/libevent-1.4.so.2
10929: trying file=/usr/lib/libevent-1.4.so.2
10929:
Then create a link to libevent-1.4.so.2 and then run memcached:
# ln -s /usr/local/servers/libevent/lib/libevent-1.4.so.2 /lib/libevent-1.4.so.2
4. Install the php memcache extension
You can use the pecl installer that comes with php
# /usr/local/servers/php5/bin/pecl install memcache
You can also install from source
# tar zxf memcache-2.2.3.tgz
# cd memcache-2.2.3
# /usr/local/servers/php5/bin/phpize
# ./configure --enable-memcache=/usr/local/servers/memcached --with-php-config=/usr/local/servers/php5/bin/php-config --with-apxs2=/usr/sbin /apxs
# make && make inst
After installation, there will be a prompt similar to this:
Installing shared extensions: /usr/local/servers/php5/lib/php/extensions/no-debug-non-zts-20060922/
Remember this, then modify php.ini and change
extension_dir = "./"
修改为
extension_dir = "/usr/local/servers/php5/lib/php/extensions/"
并添加一行
extension="no-debug-non-zts-20060922/memcache.so"
5. 用phpinfo查看
测试模块
$memcache = new Memcache;
$memcache->connect(localhost, 12000) or die ("Could not connect");
$version = $memcache->getVersion();
echo "Servers version: ".$version."
";
$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)
";
$get_result = $memcache->get(key);
echo "Data from the cache:
";
var_dump($get_result);
?>
显示结果:
Servers version: 1.2.6
Store data in the cache (data will expire in 10 seconds)
Data from the cache:
object(stdClass)[3] public str_attr => string test (length=4) public int_attr => int 123

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

In PHP8, match expressions are a new control structure that returns different results based on the value of the expression. 1) It is similar to a switch statement, but returns a value instead of an execution statement block. 2) The match expression is strictly compared (===), which improves security. 3) It avoids possible break omissions in switch statements and enhances the simplicity and readability of the code.

In PHP, you can effectively prevent CSRF attacks by using unpredictable tokens. Specific methods include: 1. Generate and embed CSRF tokens in the form; 2. Verify the validity of the token when processing the request.

The... (splat) operator in PHP is used to unpack function parameters and arrays, improving code simplicity and efficiency. 1) Function parameter unpacking: Pass the array element as a parameter to the function. 2) Array unpacking: Unpack an array into another array or as a function parameter.

In PHP, the final keyword is used to prevent classes from being inherited and methods being overwritten. 1) When marking the class as final, the class cannot be inherited. 2) When marking the method as final, the method cannot be rewritten by the subclass. Using final keywords ensures the stability and security of your code.

Strict types in PHP are enabled by adding declare(strict_types=1); at the top of the file. 1) It forces type checking of function parameters and return values to prevent implicit type conversion. 2) Using strict types can improve the reliability and predictability of the code, reduce bugs, and improve maintainability and readability.

The main reasons why you cannot log in to MySQL as root are permission problems, configuration file errors, password inconsistent, socket file problems, or firewall interception. The solution includes: check whether the bind-address parameter in the configuration file is configured correctly. Check whether the root user permissions have been modified or deleted and reset. Verify that the password is accurate, including case and special characters. Check socket file permission settings and paths. Check that the firewall blocks connections to the MySQL server.

C language conditional compilation is a mechanism for selectively compiling code blocks based on compile-time conditions. The introductory methods include: using #if and #else directives to select code blocks based on conditions. Commonly used conditional expressions include STDC, _WIN32 and linux. Practical case: Print different messages according to the operating system. Use different data types according to the number of digits of the system. Different header files are supported according to the compiler. Conditional compilation enhances the portability and flexibility of the code, making it adaptable to compiler, operating system, and CPU architecture changes.
