PHP的嵌入式脚本语言? [英] Embedded script languages for PHP?

查看:77
本文介绍了PHP的嵌入式脚本语言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有人知道可以嵌入到php中的一个很好的脚本语言?
Javascript会很受欢迎,虽然有几次尝试,但它们要么太摇晃/慢/过时(phpjs,j4p5),要么在共享主机(pecl spidermonkey)上运行起来真的很痛苦。

i was wondering if anybody knows of a nice scripting language that can be embedded into php? Javascript would be favorite and although there are several attempts they are either much too shaky/slow/outdated (phpjs, j4p5) or a real pain to get up and running on shared hosts (pecl spidermonkey).

背景是:我想有一种语言用于控制服务器上的php,但它也应该支持一些逻辑,所以yaml,xml或json只是还不够。我已经研究过LUA口译员和mediakwiki的冬季,但他们都要么依靠外部引擎,要么拥有强大的绑定功能。

The background is: I would like to have a language that is used to control php on the server but it should also support some logic, so yaml, xml or json just isn't enough. I've looked into LUA interpreters and mediakwiki's "Winter" but they all either rely on external engines or have powerful binding whatsoever.

pecl spidermonkey binding似乎是最完整的,你可以将vars,函数和整个对象注册到js-engine。有没有人知道任何可能接近我要找的系统或语言?

pecl spidermonkey binding's appears to be the most complete where you can register vars, functions and whole objects to the js-engine. Does anyone know of any system or language that might come close to what I am looking for?

最佳

rolf

推荐答案

我理解您的担忧。即使对于受信任的来源,PHP也提供了比Web请求的整个环境所需的更多访问权限。即使脚本编写者是可信任的,即使他们只能通过脚本错误来伤害自己,更容易使用的脚本编写环境也更容易让您支持。

I understand your concern. Even for trusted sources, PHP provides more access than is necessary to the whole environment of the web request. Even if the scripters are trusted and even if they can only harm themselves with a scripting error, a more constrained scripting environment would be easier for them to use and easier for you to support.

你想要一些可以沙盒化的东西,它只能访问你明确分配给它的作用域的资源,并且在在游戏中玩运行时环境而不是在PHP自己的运行环境中执行。

You want something that can be sandboxed off, that can only access resources you explicitly assign to its scope, and that executes in a "play within a play" runtime environment rather than in PHP's own.

一种方法是对用户提交的脚本使用Web模板语言。这些提供了一定量的控制(例如变量赋值),并关闭其他选项,例如,您无法编写无限循环。我在Java应用程序中使用Velocity用于此目的;我认为像Smarty这样的东西可能适用于PHP,但我没有直接使用它来实现这一目的。

One approach is to use a web templating language for user-submitted scripts. These provide a certain amount of control (variable assignment for example), and close off other options, for example you can't write an infinite loop. I've used Velocity for this purpose in Java applications; I think something like Smarty might work in PHP, but I don't have direct experience of using it for that purpose.

另一种方法,如果脚本需要做的是受域限制,则实现域特定语言(DSL)。我在这个答案中提到过。

Another approach, if what the scripts are required to do is constrained by the domain, is to implement a Domain Specific Language (DSL). I mentioned that in this answer.

除此之外,我不知道脚本语言的任何纯PHP实现。这是我自己感兴趣的东西。

Apart from that, I don't know of any pure-PHP implementations of scripting languages. It's something I'd be interested in myself.

这篇关于PHP的嵌入式脚本语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆