-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refs #4: Add PHP 7 support as it is now mature.
- Loading branch information
Showing
3 changed files
with
94 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters