在PHP 中运行JS

这天去zend网站上逛了逛, 看到一个monkeyspider 的标签,

http://devzone.zend.com/article/4704-Using-JavaScript-in-PHP-with-PECL-and-SpiderMonkey

嘿嘿, 原来是用c写了一个扩展php扩展 把spiderMonkey和php 联起来了。 照着试了试, 还真跑下来了, 拿上来分享一下。

首先是下载

http://ftp.mozilla.org/pub/mozilla.org/js/  js-1.7

http://pecl.php.net/package/spidermonkey   spidermonkey 的php扩展

  1. shell# tar -xzvf js-1.70.tar-gz
  2. shell# cd js/src
  3. shell# make -f Makefile.ref
  4. shell# mkdir -p /usr/local/include/js/
  5. shell# cp *.{h,tbl} /usr/local/include/js/
  6. shell# cd Linux_All_DBG.OBJ
  7. shell# cp *.h /usr/local/include/js/
  8. shell# cp js /usr/local/bin/
  9. shell# cp libjs.so /usr/local/lib/
  10. shell# ldconfig
  11. tar -zxvf spidermonkey.tar.gz
  12. 进入spidermonkey , php 扩展目录,
  13. yum install automake
  14. shell# phpize
  15. shell# ./configure
  16. edit spidermonkey.c
    Add to line 152 next:
    int JSVERSION_LATEST = 185;
  17. shell# make
  18. shell# make install

 

 

在make 的时候可能会报错, 那报错的那几行注释吧, 用了几个php 的struct 里没有的属性
在php.ini 里把这个扩展打开吧, 试试把

 

  1. <?php
  2. // create JavaScript context
  3. $js = new JSContext();
  4. // define PHP variables
  5. $a = 10;
  6. $b = 2;
  7. // assign variables to JavaScript context
  8. $js->assign(‘a’, $a);
  9. $js->assign(‘b’, $b);
  10. // define script code
  11. $script = <<<END
  12. c = a + b;
  13. END;
  14. // evaluate script and display result
  15. echo ”The sum of $a and $b is: ” . $js->evaluateScript($script);
  16. ?>

 

CentOS安装vnc+wine运行windows程序挂机教程

测试vps是阿里云的最低配,内存512M,带宽1M,硬盘40G(20G+20G),独立ip。系统是CentOS 5.4

1.首先安装xfce和中文支持,依次运行如下命令:
yum groupinstall xfce-4.4 -y

yum groupinstall "Chinese Support" -y
2.安装vnc服务器:
yum install vnc-server -y

yum install yum-priorities -y
3.下载并安装wine:
rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt

rpm -ivh http://syslogserver.googlecode.com/files/rpmforge-release-0.5.1-1.el5.rf.i386.rpm

yum check-update

yum --enablerepo=rpmforge install wine -y

4.启动vnc服务器以及配置
vncserver 这时会要输入两次密码,然后依次运行下面代码:

echo 'VNCSERVERS="1:root"'>>/etc/sysconfig/vncserversecho 'VNCSERVERARGS[1]="-geometry 800x600"'>>/etc/sysconfig/vncserversecho > /root/.vnc/xstartupecho '#!/bin/sh'>>/root/.vnc/xstartupecho '/usr/bin/startxfce4'>>/root/.vnc/xstartupchmod +x ~/.vnc/xstartupchkconfig vncserver on

安装成功以后,重启一下vncserver,

/etc/init.d/vncserver restart

然后通过vncviewer连接到vps,然后找到 Wine File打开 如下如:

打开Wine File以后你就会看到大家熟悉的资源管理器,接下来的就不用说了,跟windows下一样了。

测试通过:Host1free centos 6/阿里云 centos 5.4