-
Notifications
You must be signed in to change notification settings - Fork 1
toymachine/chdb
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This is the readme file for the 'chdb' php extension. chdb implements a read-only memory mapped hash-table for PHP. This is useful, because PHP, like other scripting languages does not have a concept of constant storage like 'C's data-segment. On PHP the only way to define large amounts of constants (for instance language keys -> translation) can only be done by using lot's of defines, lot's of class consts, or some humongous array structure. Even with an op-code cacher like APC or e-accelerator, defining constants this way is both CPU and memory consuming, as each instance of php will need to load/parse/execute the opcodes to define the constants for each request. If you are using PHP in a typical setup for a big website which remains stable between releases you might benefit from the chdb extension. Which chdb, you can create a disk file containing a hashmap of key-value pairs at 'deploy-time'. This disk file is then memory mapped into the memory of each php-instance at 'run-time'. Potentially this file can be huge, as only those portions that are actually read will be paged in by the operating system. Also the memory that is used will be shared by all running php-instances that have the same map 'opened'. Use the script 'perfect_hash.py' to create the hashmap at deploy-time (note this script will be ported to php in the future): python perfect_hash.py <input-file> hash.chdb This will create a hashmap 'hash.chdb' from the input file. The input file contains a key-value pair on each line with key and value seperated by a tab ('\t'). From php you can now use the hashmap like this: $chdb = chdb_open("hash.chdb"); $value = $chdb->get("SOME_KEY"); $value will === false when key is not found.
About
Constant Hash Database. A php extension implementation a read-only memory mapped Hash table
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published