{"id":13827159,"url":"https://github.com/iqbalfn/exec-php","last_synced_at":"2025-07-09T03:30:59.634Z","repository":{"id":19584140,"uuid":"22834169","full_name":"iqbalfn/exec-php","owner":"iqbalfn","description":"Execute PHP function within NodeJS application","archived":false,"fork":false,"pushed_at":"2021-12-25T05:38:30.000Z","size":51,"stargazers_count":44,"open_issues_count":0,"forks_count":8,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-09T20:17:38.884Z","etag":null,"topics":["javascript","nodejs","php"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/iqbalfn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-08-11T09:41:09.000Z","updated_at":"2023-06-03T08:34:32.000Z","dependencies_parsed_at":"2022-08-21T10:41:08.869Z","dependency_job_id":null,"html_url":"https://github.com/iqbalfn/exec-php","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/iqbalfn/exec-php","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iqbalfn%2Fexec-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iqbalfn%2Fexec-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iqbalfn%2Fexec-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iqbalfn%2Fexec-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iqbalfn","download_url":"https://codeload.github.com/iqbalfn/exec-php/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iqbalfn%2Fexec-php/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264386252,"owners_count":23599963,"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":["javascript","nodejs","php"],"created_at":"2024-08-04T09:01:51.309Z","updated_at":"2025-07-09T03:30:59.359Z","avatar_url":"https://github.com/iqbalfn.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# exec-php\n\nExecute PHP function within NodeJS application\n\n## Installation\n\n```bash\nnpm install exec-php\n```\n\n## Usage\n\n```js\nlet execPhp = require('exec-php');\n\nexecPhp('path/to/file.php', '/usr/bin/php', (err, php, out) =\u003e {\n    // the `php` argument is now contains all php defined functions\n    php.my_func(arg1, arg2, (err, res, out, print) =\u003e {\n        // `res` argument is now hold the returned value of `my_func` php function\n        // `print` hold anything that get printed during calling the `my_func` function\n    })\n})\n```\n\n## Arguments\n\n1. `phpfile::string` Path to user php file.\n1. `phpbin::string` Path to engine php binary file.\n1. `callback::function` A function to call after populating the php functions.\n\nThe `callback` function will be called with below arguments:\n\n1. `error::mixed` The error message.\n1. `php::object` The php object that hold all php defined functions.\n1. `printed::string` All printed string while populating php functions.\n\n## php Arguments\n\nAll user defined function on php engine will be appended to `php` argument of\nthe caller. The function will be **lower case**. You can now call the function\nnormally with additional last argument is the callback function to get response\nof the php functions call with below arguments:\n\n1. `error::mixed` Error message\n1. `result::mixed` Returned content of user php function\n1. `output::string` Printed string on requiring the php file.\n1. `printed::string` Printed string on calling user php function.\n\n## Example\n\n```php\n// file.php\n\u003c?php\n\necho \"One\";\nfunction my_function($arg1, $arg2){\n    echo \"Two\";\n    return $arg1 + $arg2;\n}\n```\n\n```js\n// app.js\nlet execPhp = require('exec-php');\n\nexecPhp('file.php', (err, php, out) =\u003e {\n    // outprint is now `One'.\n\n    php.my_function(1, 2, (err, result, output, printed) =\u003e {\n        // result is now `3'\n        // output is now `One'.\n        // printed is now `Two'.\n    })\n})\n```\n\n## Note\n\nAll uppercase function name on PHP will be converted to lowercase on `exec-php`.\n\n```php\n// file.php\n\u003c?php\n\nfunction MyFunction($a, $b){\n    return $a + $b;\n}\n```\n\n```js\n// app.js\nlet execPhp = require('exec-php')\n\nexecPhp('file.php', (err, php, out) =\u003e {\n    php.myfunction(1, 2, function(error, result){\n        // result is now 3\n    })\n})\n```\n\n## ChangeLog\n\n1. 0.0.3\n    1. Handle PHP throw error exception\n1. 0.0.4\n    1. Upgrade tmp module to suppress opsolete functions ( [GuilhermeReda](https://github.com/GuilhermeReda) )\n    1. Add `noop` function to support the new node callback standard\n1. 0.0.5\n    1. Close temp file pointer on removing the file ( [MHDMAM](https://github.com/MHDMAM) )\n1. 0.0.6\n    1. Remove deprecated `module.parent` ( [Jakub Zasański](https://github.com/jakubzasanski) )\n    1. Upgrade deprecated dependencies\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiqbalfn%2Fexec-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiqbalfn%2Fexec-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiqbalfn%2Fexec-php/lists"}