Home Backend Development PHP Tutorial php中apc缓存使用示例_PHP

php中apc缓存使用示例_PHP

Jun 01, 2016 am 11:58 AM
apc cache

记的以前php文件上传到服务器时需要先用zend guard加密下,有了apc就不用了。 从维基百科上看到的消息,apc将被内置在php6中,所以apc还是值的学习下的。

1、安装扩展

在ubuntu 12.04可以直接通过apt-get install php-apc安装apc扩展。

关于windows系统,笔者以前曾在windows下安装过apc,只是运行不稳定,不晓得现在解决了没有。在windows下可以用wincache替代apc,微软自己开发的,非常稳定。

Tips:安装完成后,要记的重启下web服务器。

2、下载apc.php

下载地址:apc_php.zip

apc.php这个脚本可以查看apc的使用情况。界面如下:

php中apc缓存使用示例_PHP

其中有两个选项卡可以稍微关注下:

1 System Cache Entries:这个表示系统缓存选项,都是缓存一些php文件的中间码。

2 User Cache Entries:表示用户数据的缓存,在编码中可以将用户的数据缓存到apc。如果要查看用户数据缓存,需要先修改访问的账号和密码。打开apc.php文件,找到如下两行代码进行修改就可以了:

复制代码 代码如下:
defaults('ADMIN_USERNAME','apc');    // Admin Username
defaults('ADMIN_PASSWORD','password');   // Admin Password - CHANGE THIS TO ENABLE!!!

3、apc使用示例

apc使用起来非常简单,看下面的几个增加、查询、修改、删除示例。

增加一个缓存,有效时间为3600秒

复制代码 代码如下:
apc_add('name', 'tom', 3600);

执行代码,然后查看User Cache Entries,可以看到多了一条键值为name的缓存数据:

php中apc缓存使用示例_PHP
 

其中有命中次数、大小、过期时间等等。

查询缓存

复制代码 代码如下:
apc_add('name', 'tom', 3600);
print apc_fetch('name'); //输出tom

修改缓存

复制代码 代码如下:
apc_store('name', 'anny', 3600);
print apc_fetch('name'); //输出anny

删除缓存

复制代码 代码如下:
apc_delete('name');
var_dump(apc_fetch('name')); //输出bool(false)

递增递减数字

如果缓存的内容是数字,可以用apc_ inc自增1,apc_dec自减1。

复制代码 代码如下:
apc_add('num', 10);
apc_inc('num');
print apc_fetch('num');//输出11
apc_dec('num');
print apc_fetch('num');//输出10

判断缓存是否存在

复制代码 代码如下:
apc_add('name', 'tom', 3600);
var_dump(apc_exists('name')); //输出bool(true)
var_dump(apc_exists('age')); //bool(false)


 

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Application practice of APC caching technology in PHP Application practice of APC caching technology in PHP Jun 19, 2023 pm 07:16 PM

With the development of the Internet and the increasing amount of data processing, many websites need to process a large amount of data queries and calculations, which requires an efficient caching mechanism to optimize website access speed. APC (AlternativePHPCache) is a caching technology commonly used in PHP language. It can improve the performance and response speed of the website. This article will introduce the basic principles of APC caching technology and its application practice in PHP. 1. Principle of APC caching technology APC is an open source caching technology that can

Application scenarios of using APC caching technology for dynamic data caching in PHP applications Application scenarios of using APC caching technology for dynamic data caching in PHP applications Jun 21, 2023 pm 04:01 PM

As web applications become more and more complex, dynamic data caching has become a necessary technology. APC (AlternativePHPCache), as a memory caching technology, can greatly improve the performance and response speed of web applications. This article will introduce the application scenarios of using APC caching technology for dynamic data caching in PHP applications. Data cache with high access frequency Some data are frequently accessed in web applications. If read from the database every time, application performance will be seriously affected. At this time, these can be

How to use APC for PHP data caching optimization? How to use APC for PHP data caching optimization? Aug 10, 2023 am 10:30 AM

How to use APC for PHP data caching optimization? Introduction: During the development process, we often encounter situations where we need to frequently read data from the database and process it. In this case, in order to improve performance and reduce access pressure on the database, we can use cache to store queried data. APC (AlternativePHPCache) is a commonly used PHP extension that allows us to cache data in memory to speed up PHP applications. This article will introduce how to use A

APC caching technology's solution for using cursor iteration in PHP-based applications APC caching technology's solution for using cursor iteration in PHP-based applications Jun 19, 2023 pm 11:30 PM

With the development of Internet applications, PHP, as a popular development language, is widely used in the development of Web applications. However, in actual development, we often encounter some performance bottlenecks, causing the application to be unable to meet user needs. One of the common bottlenecks is the performance problems caused by database queries. In order to solve this problem, we can use some caching technologies, among which APC caching technology is a good option. APC (AlternativePHPCache) is

PHP 7 performance optimization tips: How to use APC cache to speed up script execution PHP 7 performance optimization tips: How to use APC cache to speed up script execution Jul 29, 2023 pm 08:29 PM

PHP7 performance optimization tips: How to use APC caching to accelerate script execution Introduction: With the increasing complexity of network applications and the increasing number of users, optimizing the performance of PHP scripts has become particularly important. One common optimization method is to use caching to reduce script execution time. In PHP, APC (AlternativePHPCache) is a widely used caching tool that can significantly improve the performance of scripts. This article will introduce how to use APC caching to speed up the execution of PHP7 scripts.

Application scenarios of using APC caching technology to implement aggregated query analysis in PHP-based applications Application scenarios of using APC caching technology to implement aggregated query analysis in PHP-based applications Jun 20, 2023 pm 09:24 PM

APC caching technology is a PHP-based caching technology that can improve application performance while reducing server load. In PHP-based applications, APC caching technology can implement aggregated query analysis, improving application efficiency and user experience. Aggregated query analysis refers to merging multiple query results together to obtain more comprehensive and comprehensive data analysis results. When processing large amounts of data, aggregate query analysis can help us capture important information in the data, improve data processing efficiency, and reduce the need for server maintenance.

The optimization effect of APC caching technology on PHP application performance The optimization effect of APC caching technology on PHP application performance Jun 19, 2023 pm 06:28 PM

With the continuous development of Internet applications, more and more business logic is put into Web applications. The speed of web applications is affected by many factors, such as hardware performance, network bandwidth, database performance, etc., which need to be continuously optimized. Among them, caching technology is an optimization method widely used in Web applications, and APC caching technology is a caching technology used in PHP applications. 1. Introduction to APC caching technology. The full name of APC is AlternativePHPCach.

Benefits of using APC caching technology in PHP applications Benefits of using APC caching technology in PHP applications Jun 20, 2023 pm 09:18 PM

With the development of the Internet, PHP, as a popular web programming language, is widely used in website development and application development. In PHP applications, caching technology can improve application performance and scalability, while also reducing server load pressure. Among them, APC caching technology is one of the commonly used caching technologies, which can effectively improve the response speed and efficiency of applications. APC caching technology is a PHP built-in caching plug-in, whose full name is AlternativePHPCache. It can cache compilation

See all articles