{"id":18397302,"url":"https://github.com/php-ffi/work-directory","last_synced_at":"2025-07-02T19:32:56.609Z","repository":{"id":187281272,"uuid":"676550591","full_name":"php-ffi/work-directory","owner":"php-ffi","description":"Library to interact with current working directory","archived":false,"fork":false,"pushed_at":"2024-12-17T00:28:04.000Z","size":24,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-20T17:29:09.999Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/php-ffi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-09T13:08:51.000Z","updated_at":"2024-12-17T00:28:08.000Z","dependencies_parsed_at":null,"dependency_job_id":"fbaabc5c-b865-4cc2-a149-fbcaaab2528a","html_url":"https://github.com/php-ffi/work-directory","commit_stats":null,"previous_names":["php-ffi/work-directory"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/php-ffi/work-directory","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-ffi%2Fwork-directory","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-ffi%2Fwork-directory/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-ffi%2Fwork-directory/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-ffi%2Fwork-directory/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/php-ffi","download_url":"https://codeload.github.com/php-ffi/work-directory/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-ffi%2Fwork-directory/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261712335,"owners_count":23198183,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T02:16:39.828Z","updated_at":"2025-07-02T19:32:56.588Z","avatar_url":"https://github.com/php-ffi.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Work Directory\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://packagist.org/packages/ffi/work-directory\"\u003e\u003cimg src=\"https://poser.pugx.org/ffi/work-directory/require/php?style=for-the-badge\" alt=\"PHP 8.1+\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://packagist.org/packages/ffi/work-directory\"\u003e\u003cimg src=\"https://poser.pugx.org/ffi/work-directory/version?style=for-the-badge\" alt=\"Latest Stable Version\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://packagist.org/packages/ffi/work-directory\"\u003e\u003cimg src=\"https://poser.pugx.org/ffi/work-directory/v/unstable?style=for-the-badge\" alt=\"Latest Unstable Version\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://packagist.org/packages/ffi/work-directory\"\u003e\u003cimg src=\"https://poser.pugx.org/ffi/work-directory/downloads?style=for-the-badge\" alt=\"Total Downloads\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://raw.githubusercontent.com/php-ffi/work-directory/master/LICENSE.md\"\u003e\u003cimg src=\"https://poser.pugx.org/ffi/work-directory/license?style=for-the-badge\" alt=\"License MIT\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/php-ffi/work-directory/actions\"\u003e\u003cimg src=\"https://github.com/php-ffi/work-directory/workflows/build/badge.svg\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\nIn the case that during the loading of a binary (like `*.so`, `*.dylib` or `*.dll`)\nthrough FFI it depends on some other binary module, then errors may occur if the\nfirst one and dependent libraries are in different directories, like:\n\n```php\n// - bin/\n//   - main.dll\n//   - other/\n//     - dependency.dll\n\n$ffi = \\FFI::cdef('...', __DIR__ . '/bin/main.dll');\n// Error like \"can not load ...\"\n// - In this case, an error occurs because the specified\n//   dependency (\"dependency.dll\") could not be found in \"bin\"\n//   or working directory. \n```\n\nThis library allows you to load similar dependencies:\n\n```php\n// Use \"bin/other\" directory for dependencies.\n\\FFI\\WorkDirectory\\WorkDirectory::set(__DIR__ . '/bin/other');\n\n// \n$ffi = \\FFI::cdef('...', __DIR__ . '/bin/main.dll');\n```\n\nYou can also use the built-in [chdir function](https://www.php.net/manual/en/function.chdir.php) \nfor such operations, however it will only work in case of a Non-Thread Safe PHP \nbuild ([see remark](https://www.php.net/manual/en/function.chdir.php#refsect1-function.chdir-notes)).\n\n## Requirements\n\n- PHP \u003e= 7.4\n\n## Installation\n\nLibrary is available as composer repository and can be installed using the \nfollowing command in a root of your project.\n\n```sh\n$ composer require ffi/work-directory\n```\n\n## Usage\n\n### Get Current Work Directory\n\n```php\n$directory = \\FFI\\WorkDirectory\\WorkDirectory::get();\n\nif ($directory !== null) {\n    echo 'CWD is: ' . $directory;\n}\n```\n\n### Update Current Work Directory\n\nGetting the full path to the library.\n\n```php\n$directory = __DIR__ . '/path/to/directory';\n\nif (\\FFI\\WorkDirectory\\WorkDirectory::set($directory)) {\n    echo 'CWD has been updated to: ' . $directory;\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-ffi%2Fwork-directory","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphp-ffi%2Fwork-directory","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-ffi%2Fwork-directory/lists"}