{"id":13412722,"url":"https://github.com/deuill/go-php","last_synced_at":"2025-05-15T00:13:30.638Z","repository":{"id":41557080,"uuid":"42682742","full_name":"deuill/go-php","owner":"deuill","description":"PHP bindings for the Go programming language (Golang)","archived":false,"fork":false,"pushed_at":"2025-01-06T17:18:43.000Z","size":217,"stargazers_count":942,"open_issues_count":22,"forks_count":107,"subscribers_count":40,"default_branch":"master","last_synced_at":"2025-05-09T05:10:13.113Z","etag":null,"topics":["go","language-bindings","php"],"latest_commit_sha":null,"homepage":"","language":"Go","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/deuill.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":"2015-09-17T21:23:52.000Z","updated_at":"2025-04-24T00:12:00.000Z","dependencies_parsed_at":"2025-01-29T05:00:22.392Z","dependency_job_id":null,"html_url":"https://github.com/deuill/go-php","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deuill%2Fgo-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deuill%2Fgo-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deuill%2Fgo-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deuill%2Fgo-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/deuill","download_url":"https://codeload.github.com/deuill/go-php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254249206,"owners_count":22039029,"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":["go","language-bindings","php"],"created_at":"2024-07-30T20:01:28.344Z","updated_at":"2025-05-15T00:13:25.617Z","avatar_url":"https://github.com/deuill.png","language":"Go","readme":"# PHP bindings for Go\n\n[![API Documentation][godoc-svg]][godoc-url] [![MIT License][license-svg]][license-url]\n\nThis package implements support for executing PHP scripts, exporting Go variables for use in PHP contexts, attaching Go method receivers as PHP classes and returning PHP variables for use in Go contexts.\n\nBoth PHP 5.x and PHP 7.x series are supported.\n\n## Building\n\nBuilding this package requires that you have PHP installed as a library. For most Linux systems, this can usually be found in the `php-embed` package, or variations thereof.\n\nOnce the PHP library is available, the bindings can be compiled with `go build` and are `go get`-able.\n\n**Note**: Building against PHP 5.x requires that the `php5` tag is provided, i.e.:\n\n```bash\ngo get -tags php5 github.com/deuill/go-php\n```\n\nThis is due to the fact that PHP 7.x is the default build target.\n\n## Status\n\nExecuting PHP [script files][Context.Exec] as well as [inline strings][Context.Eval] is supported and stable.\n\n[Binding Go values][NewValue] as PHP variables is allowed for most base types, and PHP values returned from eval'd strings can be converted and used in Go contexts as `interface{}` values.\n\nIt is possible to [attach Go method receivers][NewReceiver] as PHP classes, with full support for calling expored methods, as well as getting and setting embedded fields (for `struct`-type method receivers).\n\n### Caveats\n\nBe aware that, by default, PHP is **not** designed to be used in multithreaded environments (which severely restricts the use of these bindings with Goroutines) if not built with [ZTS support](https://secure.php.net/manual/en/pthreads.requirements.php). However, ZTS support has seen major refactoring between PHP 5 and PHP 7, and as such is currently unsupported by this package.\n\nCurrently, it is recommended to either sync use of seperate Contexts between Goroutines, or share a single Context among all running Goroutines.\n\n## Roadmap\n\nCurrently, the package lacks in several respects:\n\n  * ZTS/multi-threading support. This basically means using Go-PHP in Goroutines is severely limited.\n  * Documentation and examples, both package-level and external.\n  * Performance. There's no reason to believe Go-PHP suffers from any serious performance issues in particular, but adding benchmarks, especially compared against vanilla PHP, might help.\n  * Your feature request here?\n\nThese items will be tackled in order of significance (which may not be the order shown above).\n\n## Usage\n\n### Basic\n\nExecuting a script is simple:\n\n```go\npackage main\n\nimport (\n    php \"github.com/deuill/go-php\"\n    \"os\"\n)\n\nfunc main() {\n    engine, _ := php.New()\n\n    context, _ := engine.NewContext()\n    context.Output = os.Stdout\n\n    context.Exec(\"index.php\")\n    engine.Destroy()\n}\n```\n\nThe above will execute script file `index.php` located in the current folder and will write any output to the `io.Writer` assigned to `Context.Output` (in this case, the standard output).\n\n### Binding and returning variables\n\nThe following example demonstrates binding a Go variable to the running PHP context, and returning a PHP variable for use in Go:\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    php \"github.com/deuill/go-php\"\n)\n\nfunc main() {\n    engine, _ := php.New()\n    context, _ := engine.NewContext()\n\n    var str string = \"Hello\"\n    context.Bind(\"var\", str)\n\n    val, _ := context.Eval(\"return $var.' World';\")\n    fmt.Printf(\"%s\", val.Interface())\n    // Prints 'Hello World' back to the user.\n\n    engine.Destroy()\n}\n```\n\nA string value \"Hello\" is attached using `Context.Bind` under a name `var` (available in PHP as `$var`). A script is executed inline using `Context.Eval`, combinding the attached value with a PHP string and returning it to the user.\n\nFinally, the value is returned as an `interface{}` using `Value.Interface()` (one could also use `Value.String()`, though the both are equivalent in this case).\n\n## License\n\nAll code in this repository is covered by the terms of the MIT License, the full text of which can be found in the LICENSE file.\n\n[godoc-url]: https://godoc.org/github.com/deuill/go-php\n[godoc-svg]: https://godoc.org/github.com/deuill/go-php?status.svg\n\n[license-url]: https://github.com/deuill/go-php/blob/master/LICENSE\n[license-svg]: https://img.shields.io/badge/license-MIT-blue.svg\n\n[Context.Exec]: https://godoc.org/github.com/deuill/go-php/engine#Context.Exec\n[Context.Eval]: https://godoc.org/github.com/deuill/go-php/engine#Context.Eval\n[NewValue]:     https://godoc.org/github.com/deuill/go-php/engine#NewValue\n[NewReceiver]:  https://godoc.org/github.com/deuill/go-php/engine#NewReceiver\n","funding_links":[],"categories":["开源类库","Relational Databases","Embeddable Scripting Languages","Go","脚本语言与嵌入式编程","可嵌入的脚本语言","Repositories","脚本语言与嵌入式编程`在你的go代码中嵌入其他脚本语言`","\u003cspan id=\"嵌入式脚本语言-embeddable-scripting-languages\"\u003e嵌入式脚本语言 Embeddable Scripting Languages\u003c/span\u003e"],"sub_categories":["解释器","Advanced Console UIs","Search and Analytic Databases","SQL 查询语句构建库","检索及分析资料库","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeuill%2Fgo-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeuill%2Fgo-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeuill%2Fgo-php/lists"}