{"id":19535625,"url":"https://github.com/miyako/4d-class-php","last_synced_at":"2025-02-26T04:16:45.723Z","repository":{"id":220881677,"uuid":"748492944","full_name":"miyako/4d-class-php","owner":"miyako","description":"Class to use external PHP interpreter in execute, interactive or CGI mode","archived":false,"fork":false,"pushed_at":"2024-08-22T07:39:56.000Z","size":55239,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-08T17:55:20.087Z","etag":null,"topics":["4d-class","php","system-worker"],"latest_commit_sha":null,"homepage":"https://miyako.github.io/4d-class-php/","language":"4D","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/miyako.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-01-26T04:52:09.000Z","updated_at":"2024-08-22T07:40:00.000Z","dependencies_parsed_at":"2025-01-08T18:03:07.002Z","dependency_job_id":null,"html_url":"https://github.com/miyako/4d-class-php","commit_stats":null,"previous_names":["miyako/4d-class-php"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miyako%2F4d-class-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miyako%2F4d-class-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miyako%2F4d-class-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miyako%2F4d-class-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/miyako","download_url":"https://codeload.github.com/miyako/4d-class-php/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240788773,"owners_count":19857699,"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":["4d-class","php","system-worker"],"created_at":"2024-11-11T02:19:22.110Z","updated_at":"2025-02-26T04:16:45.691Z","avatar_url":"https://github.com/miyako.png","language":"4D","funding_links":[],"categories":[],"sub_categories":[],"readme":"![version](https://img.shields.io/badge/version-20%2B-E23089)\n![platform](https://img.shields.io/static/v1?label=platform\u0026message=mac-intel%20|%20mac-arm%20|%20win-64\u0026color=blue)\n[![license](https://img.shields.io/github/license/miyako/4d-class-php)](LICENSE)\n![downloads](https://img.shields.io/github/downloads/miyako/4d-class-php/total)\n\n[Classes](https://github.com/miyako/4d-class-php/tree/main/Project/Sources/Classes) to use external PHP interpreter in execute, interactive or CGI mode.\n\n\u003cimg src=\"https://github.com/miyako/4d-class-php/assets/1725068/d470dc30-004f-4b8a-9812-32555bcd2a23\" style=\"height:360px;width:auto;\" /\u003e\n\n# Introduction\n\nThe internal PHP Interpreter has been removed in v20 R3[^removed]. Now it is \"strongly advised\" to use `4D.SystemWoker` to execute PHP code. \n\nTo effectively replace the CGI-based `PHP Execute`[^phpexecute] with `4D.SystemWoker`[^systemworker] you need to be able to do 3 things:\n\n1. Launch `php` once and keep it running\n2. Talk to the interpreter through `stdIn` and hear back from it through `stdOut` and `stdErr`\n3. Terminate the running `php` when you no longer need it\n\nFor 1. and 3. you need to keep track of the single instance of `4D.SystemWoker` that is bound to the PHP interpreter.\n\nFor 2. you need to implement a controller object and run your code in an execution context of a dialog or a worker. Ideally the controller would be a generic class that can be easily extended according to specific needs.\n\nThis project shares a set of classes to execute PHP from 4D by using an external interpeter and CGI (the `PHP Execute` command), interactive mode, or one-shot execute mode. \n\n# Install\n\nGet PHP from the offical site for Windows[^phpforwindows] or from my repository[^phpformac] for macOS. Alternatively, compile PHP from source. Place `php` and/or `php-cgi` at the following path:\n\n```path\n/RESOURCES/bin/{platform}/\n```\n\n# Examples\n\n## Execute\n\n```4d\n$ini:=File(\"/RESOURCES/php/php.ini\")\n$PHP:=cs.PHP.new(cs._PHP_Controller; $ini)\n$PHP.run($input)\n//the data is returned synchronously\n$stdOut:=$PHP.data\n```\n\n## Interactive\n\n```4d\n$ini:=File(\"/RESOURCES/php/php.ini\")\n$PHP:=cs.PHP.new(cs._PHP_Controller; $ini)\n$PHP.interactive()\n//you can now post messages and receive data asynchronously\n$PHP.controller.worker.postMessage($input+\"\\r\\n\")\n```\n\n## CGI\n\n```4d\n$ini:=File(\"/RESOURCES/php/php.ini\")\n$CGI:=cs.PHP_CGI.new(cs._PHP_CGI_Controller; $ini).cgi()\n//you can now use PHP Execute\n```\n\n[^removed]: [Deprecation of PHP Commands \u0026 Removal of 4D Built-in PHP Interpreter](https://blog.4d.com/deprecation-of-php-commands-removal-of-4d-built-in-php-interpreter/)\n\n[^phpexecute]: [4D v20 R3 \u003e 4D Language Reference \u003e PHP \u003e PHP Execute](https://doc.4d.com/4Dv20R3/4D/20-R3/PHP-Execute.301-6531696.en.html)\n\n[^systemworker]: [Core Development \u003e Class Functions \u003e SystemWorker](https://developer.4d.com/docs/20-R3/API/SystemWorkerClass)\n\n[^phpforwindows]: [PHP For Windows](https://windows.php.net)\n\n[^phpformac]: [miyako/4d-topic-php](https://github.com/miyako/4d-topic-php/releases)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiyako%2F4d-class-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmiyako%2F4d-class-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiyako%2F4d-class-php/lists"}