go开发一个php服务器,Goro:这是PHP的一个实现,用纯Go编写

该项目是一个尝试使用纯Go实现PHP的早期版本,目标是引入Go的并发特性、更好的缓存机制、内存管理和安全的沙箱执行环境。目前包括PHP CLI的实现,但核心功能仍不完整,待解决的问题包括参数处理、错误报告和多种扩展的支持。该项目鼓励社区参与,共同完善PHP的Go实现。
摘要由CSDN通过智能技术生成

Goro

68747470733a2f2f7472617669732d63692e6f72672f4d61676963616c5475782f676f726f2e73766768747470733a2f2f676f646f632e6f72672f6769746875622e636f6d2f4d61676963616c5475782f676f726f2f636f72653f7374617475732e73766768747470733a2f2f696d672e736869656c64732e696f2f62616467652f636861742d74656c656772616d2d626c75652e7376673f6c6f676f3d74656c656772616d266c6f676f436f6c6f723d7768697465

This is an implementation of PHP, written in pure Go (as much as possible, right now pcre doesn't exist in pure go and require usage of libpcre).

Why?

That's a good question. PHP is a nice language but is having trouble keeping up with modern languages. This implementation, while far from finished, is trying to make a number of things possible:

Usage of goroutines, go channels, etc from within PHP

Better caching of compiled code by allowing sharing of compiled or live objects (classes, objects, etc) between running PHP scripts

Use Go's memory management within PHP

Ability to run functions or code sandboxed (including filesystem) to limit security risks

Easily call the PHP engine from Go to execute pieces of PHP code (user provided or legacy)

Install

In order to run php code as cli:

go get github.com/MagicalTux/goro/sapi/php-cli

Status

This is still a very early implementation and most of the core is missing.

TODO

The following needs to be done before we can call this an alpha version.

Fix arguments passed by reference for builtin methods

Error reporting, lower level of errors (warnings, etc)

php.ini handling

Streams & filesystem support

command line flags handling

Class and object implementation is still very early. Access checks are missing. Class inheritance, etc are missing

Class abstract

Builtin class methods

Interfaces

Exception throwing

Traits

break/continue needs improvement/fixing

declare

goto ?

namespaces

generators

predefined superglobals

Allow process to run in containers on linux (see https://github.com/lizrice/containers-from-scratch - would be useful to create a play interface for goro)

Extensions

Sorted by priority.

Extension

Status

Notes

standard

5%

a lot of work remaining

json

33%

Need custom impl to support php arrays

pcre

5%

currently using cgo version of libpcre

session

date

1%

SPL

iconv

using golang.org/x/text/transform

curl

using net/http

hash

50%

mysqli

gmp

20%

Using math/big

mbstring

mcrypt

openssl

using crypto packages

Reflection

tokenizer

already in core/tokenizer, needs to be exposed

xml...

gd

without gd

bz2

1%

zlib

calendar

Phar

ctype

100%

sockets

Concepts

Process

A process object will typically be created only once in a runtime environment, and is used to keep some objects cached, as well as global stream wrapper resources. Persistant connections, run time cache, etc are stored at the Process level.

GlobalCache (optional)

A special global status intermediate between Process and Global that causes declarations of classes and functions to be kept between scripts, typically useful when using an autoloader.

Global

When a request is received or execution of a script is requested, a new Global context is created. The global context contains runtime level details such as global variables, declared functions, classes, constants, etc.

Context

Context is a local context, such as within a running function etc. Global has a root context, and each function call causes instantiation of a new context so that variables space is kept separated.

Contributing

A lot of work is needed. The most important part is improving the documentation, followed by improving support of core features (see TODO in this file), and implement individual functions from the various PHP extensions.

Writing an extension is simple. Create a directory in ext, write code prefixed with a magic function defining comment and run the tools/buildext.php script to generate bindings/etc. Add your newly created extension to the main.go of each sapi to enable it by default.

Before contributing, please join the telegram group and/or create an issue on github in order to discuss and find out which parts you can work on and how to proceed.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值