Skip to content

Commit

Permalink
refs #4: Add PHP 7 support as it is now mature.
Browse files Browse the repository at this point in the history
  • Loading branch information
achimnol committed Jun 27, 2016
1 parent 0728ae5 commit a86fefa
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 4 deletions.
6 changes: 3 additions & 3 deletions php7/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:14.04
FROM ubuntu:16.04
MAINTAINER Joongi Kim "[email protected]"

# Add an isolated user
Expand All @@ -21,10 +21,10 @@ RUN sed -i 's/archive\.ubuntu\.com/kr.archive.ubuntu.com/' /etc/apt/sources.list
RUN apt-get update && apt-get upgrade -y
RUN apt-get install -y language-pack-en-base python-software-properties software-properties-common
ENV LC_ALL=en_US.UTF-8
RUN add-apt-repository ppa:ondrej/php-7.0 && apt-get update
RUN apt-get install -y git-core wget php7.0-cli php7.0-gd php7.0-sqlite3 php7.0-dev php-pear
RUN apt-get install -y php7.0-cli php7.0-gd php7.0-sqlite3 php7.0-dev php-pear
RUN apt-get install -y pkg-config libzmq3-dev
RUN echo '' | pecl install zmq-beta
RUN echo 'extension=zmq.so' > /etc/php/7.0/cli/conf.d/20-zmq.ini

# Secure installation scripts
USER root
Expand Down
75 changes: 74 additions & 1 deletion php7/run.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,76 @@
<?php

# TODO: implement!
# This class hides REPL's variable scope from user codes.
class CodeExecutor {
public function execute($code) {
$f = function () use ($code) { eval($code); };
$f = $f->bindTo(null);
$f();
}
}

function _main() {

$exceptions = array();

$errhandler = function ($errlvl, $errstr, $errfile, $errline, $errcontext)
use (&$exceptions)
{
array_push($exceptions, array(
"$errstr (Line: $errline)",
array(),
false,
NULL
));
return true; # do NOT continue PHP's own error processing
};

$exchandler = function ($ex) use (&$exceptions)
{
$exc_name = get_class($ex);
array_push($exceptions, array(
"$exc_name",
array($ex->getMessage()),
false,
$ex->getTraceAsString()
));
};

chdir('/home/work');

$context = new ZMQContext();
$server = new ZMQSocket($context, ZMQ::SOCKET_REP);
$server->bind('tcp://*:2001');
echo 'serving at port 2001...';

while (true) {
$data = $server->recvMulti();

$exceptions = array(); # reinit the array
set_error_handler($errhandler);
ob_start();

try {
# $data[0] (cell_id) is unused currently.
$c = new CodeExecutor();
$c->execute($data[1]);
} catch (Exception $ex) {
$exchandler($ex);
} finally {
$output = ob_get_flush();
restore_error_handler();
$stderr = NULL;
$reply = array(
'stdout' => $output,
'stderr' => $stderr,
'exceptions' => $exceptions
);
$server->send(json_encode($reply));
}
}

}

_main();

# vim: ts=8 sts=4 sw=4 et
17 changes: 17 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,23 @@ def basic_failure(self):
yield '$x = 0 / 0;', ('Division by zero', None)


class PHP7ImageTest(ImageTestBase, unittest.TestCase):

image_name = 'kernel-php7'

def basic_success(self):
yield 'echo "hello world";', 'hello world'
yield '$a = 1; $b = 2; $c = $a + $b; echo "$c";', '3'
yield 'echo isset($my_nonexistent_variable) ? "1" : "0";', '0'
# checks if our internal REPL code is NOT exposed.
yield 'echo isset($context) ? "1" : "0";', '0'
yield 'global $context; echo isset($context) ? "1" : "0";', '0'

def basic_failure(self):
yield 'throw new Exception("asdf");', ('Exception', 'asdf')
yield '$x = 0 / 0;', ('Division by zero', None)


class Nodejs4ImageTest(ImageTestBase, unittest.TestCase):

image_name = 'kernel-nodejs4'
Expand Down

0 comments on commit a86fefa

Please sign in to comment.