laravel-liberu / php-gedcom
A GEDCOM file parser (read + write) for PHP 8.4+
Fund package maintenance!
liberu-genealogy
Installs: 2 333
Dependents: 0
Suggesters: 0
Security: 0
Stars: 76
Watchers: 4
Forks: 45
Open Issues: 0
Requires
- php: >=8.4
- ext-mbstring: *
- raza9798/siteconfig: ^3.2
Requires (Dev)
- driftingly/rector-laravel: ^1.0
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^11.0
- rector/rector: ^1.0
- squizlabs/php_codesniffer: ^3.8
- dev-main
- v4.0.0
- v3.2.3
- v3.2.2
- v3.2.1
- v3.2.0
- v3.1.0
- v3.0.0
- v2.2.0
- v2.1.0
- v2.0.6
- v2.0.5
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- v1.4.10
- v1.4.9
- v1.4.8
- v1.4.7
- v1.4.6
- v1.4.5
- v1.4.4
- v1.4.3
- v1.4.2
- v1.4.1
- v1.4
- v1.3.17
- v1.3.16
- v1.3.15
- v1.3.14
- v1.3.13
- v1.3.12
- v1.3.11
- v1.3.10
- v1.3.9
- v1.3.8
- v1.3.7
- v1.3.6
- v1.3.5
- v1.3.4
- v1.3.3
- v1.3.2
- v1.3.1
- v1.3.0
- v1.2.7
- v1.2.6
- v1.2.5
- v1.2.4
- v1.2.3
- v1.2.2
- v1.2.1
- v1.2.0
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-sweep/Enhance-GEDCOM-Parser-with-Core-Parsing-Functionality
- dev-sweep/Modernize-RepoRef-Parser-and-Writer-with-PHP-8-Features-and-Code-Cleanup
- dev-sweep/Modernize-PHP-GEDCOM-Library-PHP-8-4-Support-and-Code-Quality-Improvements
- dev-sweep/Modernize-PHP-GEDCOM-Parser-and-Writer-with-Type-Hints-and-Code-Improvements
- dev-sweep/Modernize-PHP-GEDCOM-Library-with-Type-Safety-and-Strict-Typing
- dev-sweep/Refactor-and-Clean-Up-WriterTest-for-PHP-GEDCOM-Library
- dev-sweep/Enhance-Test-Infrastructure-and-Namespace-Organization-in-PHP-GEDCOM-Library
- dev-sweep/Update-PHP-Version-Support-and-Development-Dependencies
- dev-sweep/psr4_ecc88
- dev-sweep/add_status_badge_to_readmemd_for_runtest
- dev-sweep/create_github_workflow_to_run_phpunit_us
- dev-sweep/docstrings-addition_1a773
- dev-sweep/unit-tests-dataoptimizer-sour
- dev-sweep/fix-typo-in-function-name
- dev-sweep/unit-tests-for-new-logic
- dev-sweep/docstrings-enhancement
- dev-sweep/improve_codebase_for_modularization_and
- dev-sweep/add-docstrings-to-writer-test
- dev-sweep/add-unit-tests-writer-test
- dev-sweep/add-docstrings-to-writer
- dev-sweep/refactor-convert-method
- dev-sweep/add-unit-tests_62a15
- dev-sweep/docstrings-addition_ba099
- dev-sweep/add-docstrings
- dev-sweep/psr4
- dev-sweep/refactor-writer-test
- dev-sweep/write_full_tests
- dev-sweep/docstrings-addition
- dev-sweep/docstring-addition
- dev-sweep/convert-method
- dev-sweep/refactor-parser-tests
- dev-sweep/add-unit-tests
- dev-sweep/add-unit-tests-convert-method-writer
- dev-sweep/add-parser-tests
- dev-sweep/add-docstring-to-convert-function
- dev-sweep/refactor-writer-modularity
- dev-sweep/multiple_events_of_same_type
- dev-sweep/missing_data_element
- dev-sweep/your_example_does_not_work
- dev-sweep/revert-convert-method-changes
- dev-sweep/refactor_codebase_to_use_php_83
- dev-sweep/add-sweep-config
- dev-master
This package is auto-updated.
Last update: 2025-09-07 17:35:58 UTC
README
Requirements
- php-gedcom 2.0+ requires PHP 8.3 (or later). GEDCOM 5.5.1 only
- php-gedcom 3.0+ requires PHP 8.4 (or later). GEDCOM 5.5.1 only
- php-gedcom 4.0+ requires PHP 8.4 (or later). GEDCOM 5.5.1 and GEDCOM X with performance optimizations
Installation
There are two ways of installing php-gedcom.
Composer
To install php-gedcom in your project using composer, simply add the following require line to your project's composer.json
file:
{
"require": {
"liberu-genealogy/php-gedcom": "2.0.*"
}
}
Download and __autoload
If you are not using composer, you can download an archive of the source from GitHub and extract it into your project. You'll need to setup an autoloader for the files, unless you go through the painstaking process if requiring all the needed files one-by-one. Something like the following should suffice:
spl_autoload_register(function ($class) { $pathToGedcom = __DIR__ . '/library/'; // TODO FIXME if (!substr(ltrim($class, '\\'), 0, 7) == 'Gedcom\\') { return; } $class = str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php'; if (file_exists($pathToGedcom . $class)) { require_once($pathToGedcom . $class); } });
Performance Optimizations (PHP 8.4+)
php-gedcom 4.0+ includes significant performance improvements leveraging PHP 8.4 features:
Key Optimizations
- Streaming Parsers: Automatic streaming for large files (>100MB) to reduce memory usage
- Intelligent Caching: LRU cache with file modification tracking and automatic invalidation
- Property Hooks: Lazy initialization of parsers and generators using PHP 8.4 property hooks
- Optimized JSON Processing: Enhanced JSON parsing with streaming support for large Gedcom X files
- Memory Efficiency: Reduced memory footprint through optimized data structures
Performance Features
- Caching System: Automatic caching of parsed files with configurable TTL and size limits
- Large File Support: Streaming parsers handle files of any size without memory exhaustion
- Format Detection: Fast file format detection with content analysis
- Batch Operations: Optimized array operations using PHP 8.4 features
Benchmarking
Run performance benchmarks to measure improvements:
# Basic benchmark php examples/cli/performance-benchmark.php sample.ged # Full benchmark with streaming and report php examples/cli/performance-benchmark.php large.ged --streaming --report # Save baseline for comparison php examples/cli/performance-benchmark.php test.ged --baseline # Compare with baseline php examples/cli/performance-benchmark.php test.ged --compare
Cache Configuration
use Gedcom\GedcomResource; // Enable caching with custom configuration $resource = new GedcomResource( cacheEnabled: true, cacheConfig: [ 'memory_items' => 2000, // Max items in memory cache 'cache_dir' => '/tmp/gedcom', // Cache directory 'ttl' => 7200 // Cache TTL in seconds ] ); // Get cache statistics $stats = $resource->getCacheStats(); echo "Memory items: " . $stats['memory_items'] . "\n"; // Clear cache when needed $resource->clearCache();
Usage
To parse a GEDCOM file and load it into a collection of PHP Objects, simply instantiate a new Parser object and pass it the file name to parse. The resulting Gedcom object will contain all the information stored within the supplied GEDCOM file:
$parser = new \Gedcom\Parser(); $gedcom = $parser->parse('tmp.ged'); foreach ($gedcom->getIndi() as $individual) { $names = $individual->getName(); if (!empty($names)) { $name = reset($names); // Get the first name object from the array echo $individual->getId() . ': ' . $name->getSurn() . ', ' . $name->getGivn() . PHP_EOL; } }
Contributing
Pull requests are welcome, as are issues.
License
MIT License (see License.md). This means you must retain the copyright and permission notice is all copies, or substantial portions of this software.