laravel-liberu / php-gedcom
A GEDCOM file parser (read + write) for PHP 8.4+
Fund package maintenance!
liberu-genealogy
Installs: 2 357
Dependents: 0
Suggesters: 0
Security: 0
Stars: 76
Watchers: 3
Forks: 47
Open Issues: 1
pkg:composer/laravel-liberu/php-gedcom
Requires
- php: >=8.3
- ext-mbstring: *
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.2.0
- v4.1.1
- v4.1.0
- 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-copilot/improve-performance-and-tests
- dev-copilot/fix-phpunit-tests-upgrade
- dev-copilot/add-gedcom-format-version-7-0
- dev-copilot/add-gedcom-to-gedcomx-mapping
- dev-copilot/map-gedcom-to-gedcom-x
- 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: 2026-02-15 21:10:21 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, GEDCOM 7.0 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();
GEDCOM Format Support
php-gedcom 4.0+ supports both GEDCOM 5.5.1 and GEDCOM 7.0 formats. The library automatically detects the version when parsing and can write to either format.
Parsing GEDCOM Files
The parser automatically handles both GEDCOM 5.5.1 and 7.0 formats:
$parser = new \Gedcom\Parser(); // Parse a GEDCOM 5.5.1 file $gedcom551 = $parser->parse('family_tree_551.ged'); // Parse a GEDCOM 7.0 file $gedcom70 = $parser->parse('family_tree_70.ged'); // Check the version $head = $gedcom70->getHead(); $gedc = $head->getGedc(); $version = $gedc->getVersion(); // Returns "7.0" or "5.5.1"
Writing GEDCOM Files
You can export to either format by specifying the format constant:
use Gedcom\Writer; // Write as GEDCOM 5.5.1 (default) $output551 = Writer::convert($gedcom, Writer::GEDCOM55); file_put_contents('output_551.ged', $output551); // Write as GEDCOM 7.0 $output70 = Writer::convert($gedcom, Writer::GEDCOM70); file_put_contents('output_70.ged', $output70);
Version-Specific Features
The library handles version-specific features automatically:
| Feature | GEDCOM 5.5.1 | GEDCOM 7.0 |
|---|---|---|
| Unique Identifier | _UID (custom tag) |
UID (standard tag) |
| Source Data Date | Not supported | DATE subfield |
| Source Data Text | Not supported | TEXT subfield |
When writing to a specific format:
- GEDCOM 5.5.1: Outputs
_UIDtags for unique identifiers - GEDCOM 7.0: Outputs
UIDtags for unique identifiers
The parser reads both tag types, ensuring compatibility when converting between versions.
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.