Upgrading QQ Membership Activity Management System (AMS) from PHP 5.2/Apache 2.0 to PHP 7 and Apache 2.4: Process, Risks, and Performance Gains
This article details the end‑to‑end migration of the QQ Membership Activity Management System from an outdated PHP 5.2/Apache 2.0 stack to PHP 7 and Apache 2.4, covering pre‑research on HHVM and JIT, architectural choices, upgrade risks, step‑by‑step implementation, debugging techniques, API changes, and the resulting performance improvements.
Authors: Xu Hanbin, Wang Mohan, Liao Shengmao, Kuang Suwen, Liao Zengkang, Wu Zemin
Source: CSDN
1. PHP7 Learning and Pre‑research
1.1 HHVM and JIT
In 2015 the team evaluated Facebook’s HHVM, which uses Just‑In‑Time compilation to boost PHP execution speed by 5‑10× compared with native PHP 5. However, HHVM introduced compatibility and operational costs, and the anticipated JIT benefits were not universal across workloads.
1.2 PHP7 Performance Optimizations
Key improvements in PHP 7 include:
Replacing struct‑based basic variables with unions to reduce memory usage.
Allocating zend_array and zend_string contiguously to lower CPU cache‑miss rates.
Using macros and inline functions to eliminate function‑call overhead.
Further details are available in the referenced article “PHP7 Innovation and Performance Optimization”.
2. Background of AMS Platform Technology Selection
The AMS platform handles billions of daily CGI requests. Upgrading directly to HHVM or PHP 7 was considered; PHP 7 was chosen for its strong backward‑compatibility with existing code.
3. Risks and Challenges of the PHP7 Upgrade
Major challenges include:
Large version gap (Apache 2.0/PHP 5.2 → Apache 2.4/PHP 7) causing compatibility issues.
Legacy tphplib extensions lacking thread‑safety and requiring recompilation.
Potential syntax incompatibilities despite PHP 7’s 99% backward‑compatibility claim.
Uncertainties in new software stability and defects.
Although Nginx offers better concurrency, the team retained Apache due to operational familiarity.
4. Upgrade Implementation Process
4.1 High‑gap Version Upgrade Strategy
The team first migrated Apache 2.0 → Apache 2.2, validated stability, then proceeded to Apache 2.4. Similarly, PHP 5.2 → PHP 5.6 → PHP 7 was performed in stages.
Apache 2.4 was compiled with dynamic MPM support (prefork/worker/event) using the flag --enable-mpms-shared=all .
4.2 Debugging Methods
During extension recompilation, the following techniques were used:
Inserting var_dump/exit statements in PHP code.
Attaching GDB to the Apache process ( gdb -p <pid> ) to analyze core dumps.
Using strace -Ttt -v -s1024 -f -p <pid> for system‑call tracing (requires root).
5. PHP7 Extension Upgrade Practices
5.1 Data Type Changes
zval : The double‑pointer zval** is replaced by zval* ; macros like ALLOC_ZVAL and MAKE_STD_ZVAL are removed.
typedef union _zend_value {
zend_long lval;
double dval;
zend_refcounted *counted;
zend_string *str;
zend_array *arr;
zend_object *obj;
zend_resource *res;
zend_reference *ref;
zend_ast_ref *ast;
zval *zv;
void *ptr;
zend_class_entry *ce;
zend_function *func;
struct { uint32_t w1; uint32_t w2; } ww;
} zend_value;Integer : long becomes zend_long (64‑bit on 64‑bit platforms, 32‑bit otherwise).
String : Replaced by zend_string with helpers ZSTR_VAL(str) and ZSTR_LEN(str) .
zend_string *zstr = zend_string_init("test", sizeof("test"), 0);
char *cstr = ZSTR_VAL(zstr);
size_t slen = ZSTR_LEN(zstr);Custom Objects : The zend_object must be the last member of the custom struct.
struct clogger_object {
CLogger *logger;
zend_object std; // placed last
};
static inline clogger_object *php_clogger_object_from_obj(zend_object *obj) {
return (clogger_object*)((char*)obj - XtOffsetOf(clogger_object, std));
}Arrays : New hash table structures use zend_string *key and zval val . Traversal example:
ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(arr), key, item) {
// process key and item
} ZEND_HASH_FOREACH_END();5.2 API Changes
Duplicate parameters were removed from string APIs; MAKE_STD_ZVAL is obsolete; ZEND_RSRC_DTOR_FUNC now receives zend_resource * instead of zend_rsrc_list_entry * ; all Z_*_PP macros were eliminated.
6. Performance Results of the AMS PHP7 Upgrade
After completing the upgrade in late April 2016 and rolling out a gradual gray‑release, the platform showed roughly a 2× improvement in CPU usage and request throughput, matching the expected gains from PHP 7. The adoption of Apache 2.4’s Event MPM further enhanced concurrency handling.
7. Conclusion
The PHP 7 migration project, spanning over a year of research and a multi‑stage rollout, successfully modernized the AMS platform, delivering significant performance benefits, reduced hardware costs, and a more maintainable codebase. The experience underscores PHP 7’s impact on large‑scale web services.
Architecture Digest
Focusing on Java backend development, covering application architecture from top-tier internet companies (high availability, high performance, high stability), big data, machine learning, Java architecture, and other popular fields.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.