PHP’s capabilities can be significantly extended through compiled modules known as extensions. Below is a curated overview of widely adopted extensions grouped by functional domain, along with concise descriptions and practical usage notes.
Database Connectivity
-
PDO — A database abstraction layer offering consistent APIs across multiple backends (e.g., MySQL, PostgreSQL, SQLite). Enables driver-agnostic queries and prepared statements via
PDOStatement. -
mysqli — A dedicated MySQL client extension supporting both procedural and object-oriented interfaces. Features include asynchronous queries, stored procedure calls, and transaction control via
mysqli_begin_transaction(). -
pgsql — Native PostgreSQL interface providing functions like
pg_connect(),pg_query_params()for parameterized execution, andpg_fetch_all()for result set handling. -
sqlite3 — Embedded relational database engine with zero-configuration setup. Supports WAL mode, full-text search, and in-memory databases via
new SQLite3(':memory:').
Caching Mechanisms
-
APCu — User-space in-process cache optimized for high-frequency read operations. Stores serialized values using keys; supports TTL and atomic increment/decrement.
-
memcached — Client libray for distributed key-value caching systems. Implements consistent hashing and binary protocol support. Requires external memcached daemon.
-
redis — Full-featured Redis client enabling access to data structures beyond strings: hashes (
hSet,hGetAll), sorted sets (zAdd,zRangeByScore), pub/sub, and Lua scripting.
Image Manipulation
-
gd — Lightweight raster graphics library supporting dynamic image generation, resizing, alpha blending, and format conversion (JPEG, PNG, WebP, GIF). Functions like
imagecreatefrompng()andimagefilter()are commonly used. -
imagick — Wrapper around ImageMagick’s C API. Offers advanced features such as color profiles, EXIF metadata editing, PDF rendering, and non-destructive layer compositing.
Cryptography & Security
-
openssl — Interface to OpenSSL toolkit for TLS handshaking, X.509 certificate validation, and symmetric/asymmetric encryption (e.g.,
openssl_encrypt(),openssl_pkey_get_private()). -
sodium — Modern cryptographic primitives built on libsodium: authenticated encrypsion (
sodium_crypto_aead_xchacha20poly1305_ietf_encrypt()), password hashing (sodium_crypto_pwhash_str()), and constant-time comparisons.
Data Serialization
- json — Native JSON encoder/decoder (
json_encode(),json_decode()) with strict RFC 7159 compliance, depth limits, and error reporting viajson_last_error_msg().
File Handling
-
fileinfo — MIME type detection based on file content rather than extension using libmagic. Returns accurate types even for disguised or malformed files.
-
zip — Full ZIP archive manipulation: reading entries, extracting subsets, adding encrypted files, and streaming large archives without full memory loading.
HTTP & Web Services
-
curl — Multi-protocol client supporting HTTP/2, cookie persistence, connection reuse, and custom headers. Handles redirects, timeouts, and SSL verification out-of-the-box.
-
soap — WSDL-driven SOAP client/server implementation. Generates proxy classes from definitions and handles complex types, faults, and WS-* standards like WS-Security.
Internationalization & Text Processing
-
mbstring — Unicode-aware string operations: case conversion (
mb_strtoupper()), substring extraction (mb_substr()), encoding detection (mb_detect_encoding()), and regex with UTF-8 support (mb_ereg()). -
intl — ICU-based internationalization tools: locale-sensitive collation (
Collator::sort()), number/currency formatting (NumberFormatter), transliteration, and calendar arithmetic. -
bcmath — Arbitrary-precision decimal arithmetic ideal for financial calculations. Supports scale-aware division (
bcdiv()), modular exponentiation (bcpowmod()), and comparison (bccomp()).
Installation Overview
Linux (Debian/Ubuntu):
sudo apt update && sudo apt install php-curl php-mbstring php-sqlite3
sudo systemctl reload apache2
Linux (RHEL/CentOS):
sudo dnf install php-gd php-intl php-bcmath
sudo systemctl restart php-fpm
Via PECL (cross-platform):
pecl install redis
# Then add to php.ini:
extension=redis.so
Windows: Copy .dll files (e.g., php_redis.dll) into the ext/ directory, then enable in php.ini:
extension=php_redis.dll
Verification:
Run php -m | grep -i redis from CLI, or use extension_loaded('redis') in script context.