Skip to content

Instantly share code, notes, and snippets.

@chobie
Created April 25, 2012 22:19
Show Gist options
  • Save chobie/2493950 to your computer and use it in GitHub Desktop.
Save chobie/2493950 to your computer and use it in GitHub Desktop.
php-mruby gets started!

php-mruby gets started!

you know mruby is the lightweight implementation of the Ruby language. it also works with php. I made this extension in my lunch time :)

git clone https://github.com/chobie/php-mruby.git --recursive
cd php-mruby
cd mruby
make
cd ../
phpize
./configure
make
make install
# add `extension=mruby.so` to your php.ini

All right, then you can use mruby on your PHP.

<?php
$mruby = new MRuby();
$mruby->assign('$name','php-mruby');

$mruby->run(<<<'EOH'
require 'php'

def say_hello
  PHP::echo "Hello " + $name + "!"
end

say_hello
EOH
);

okay, then let's start cli-server. and access to localhost:8888

php -S localhost:8888 mruby.php

now you can see awesome message in your browser.

Hello php-mruby!

Basically, php wraps their outputs so you have to use PHP::echo instead of puts if you want to output something. (puts works fine but it outputs STDOUT.)

please fork and send a pull request if you get involved php-mruby. https://github.com/chobie/php-mruby

hope you enjoy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment