Code Monkey home page Code Monkey logo

phpphp's Introduction

PHPPHP

YO DAWG

A PHP VM implementation written in PHP.

This is a basic VM implemented in PHP using the AST generating parser developed by @nikic

To see what's supported so far, check out the opcodes.

Right now, functions (definitions and calls) are supported, if statements (with basic boolean operations), if statements, as are variables and some basic variable operations...

To see the current state of the implementation versus the Core Language Test Suite, check out the test results file.

Installation

To get the dependencies you need to use composer:

curl -s https://getcomposer.org/installer | php
php composer.phar install

Grab a cup of coffee while it runs, as it will fetch the entire PHP source code in the process which can take a while (~10 minutes).

Usage

Linux/OSX

Use the php.sh shell script to invoke php.php. This requires that php be in your system path.

./php.sh -r "var_dump('foo');"

Windows

Use the php.bat shell script to invoke php.php. This requires that php.exe be in your system path.

php.bat -r "var_dump('foo');"

Manual

You can run the implementation from the command line using the php.php file directly.

php php.php -r "var_dump('foo');"

Or with a file:

php php.php ../test.php

It only supports relative includes off the base file now (no include path parsing yet)...

Testing

run-tests

To run the test suite (which mostly fails right now), install composer using the --dev flag (to install the test suite along side php's source code). Then use the run-tests.(sh|bat) file to execute them.

Linux/OSX

./run-tests.sh

Windows

Before running tests on Windows, some lines must be removed or commented out from runtests.php (if installed via composer it will be located in vendor/php/php-src/runtests.php). Starting from line 185:

if (function_exists('is_executable') && !is_executable($php)) {
    error("invalid PHP executable specified by TEST_PHP_EXECUTABLE  = $php");
}

To run test suite simply type

run-tests.bat

Manual

If you choose not to install php's source code from composer, but have it elsewhere in your system path, you can use it directly.

php path/to/runtests.php -p path/to/php.sh path/to/tests

TODO:

Major things left to do:

  1. Implement references properly
  2. Implement Error Handling
  3. Implement classes and objects
  4. Implement Output Buffering.
  5. Refactor output control to use SAPI modules
  6. Implement true array hash tables (as opposed to the current reliance on the underlying hash table)
  7. Implement Error Handling
  8. Implement Exception Handling
  9. Implement parameter parsing for core functions

For The Love Of God, Why?

There are a number of reasons why I did this...

  1. It was something that I always wanted to do. For no particular reason other than I wanted to do it. I knew it was possible, but possible and doing it are two very different things.
  2. It was far easier than I thought. The time to the initial commit (basic working VM) was only about 6 hours of work. So it's not like I spent a year building it...
  3. It could be a useful education tool. For me learning the intricacies of the Zend VM better (I know it fairly well, but knowing and building give two different amounts of knowledge). But also for teaching others how the VM works. By giving a PHP implementation reference, hopefully more people can understand how the C implementation works (they both operate off the same generic implementation at this point).
  4. It can enable certain interesting things. For example, we could hypothetically build an Opcode optimizer in PHP which parses the generated opcodes and optimizes things (removing redundant opcodes, statically compiling static expressions, etc). Then, we could build a PECL extension that would render those optimized opcodes directly into APC cache (or some other opcode cache mechanism).
  5. It can be used to quickly mock up future functionality changes. Consider that it's easier to alter a PHP VM simply because you don't need to worry about memory management at all. So whipping up a POC for a significant feature should be a lot easier in PHP than C (at least for many non-full-time C developers).
  6. It can be used to actually debug PHP code without working knowledge of GDB (and the underlying C structures). I wouldn't recommend this, as the chances of us getting it working 100% the same as the C implementation are practically 0, but it's a concept.
  7. It could wind up becoming a full implementation (like PYPY). If we can compile the implementation using HipHop, and do some other lower-level tricks, there's a chance we could achieve performance somewhere near the C implementation. I doubt it, but it's possible. Especially if we add a JIT component (or a way of rendering out to machine code certain opcodes)...
  8. Why not?

About The Authors

Anthony Ferrara - @ircmaxell blog.ircmaxell.com

Nikita Popov - @nikita_ppv nikic.github.com

phpphp's People

Contributors

arnaud-lb avatar cystbear avatar igorw avatar ircmaxell avatar lyrixx avatar nikic avatar pinscript avatar rickysu avatar srsbiz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

phpphp's Issues

Apache and Opcode caches integration

This is more of a question but there is a "question" tag in Github issues so:

If it was possible to integrate PHPPHP to Apache (or any server) like PHP, and if it was possible for PHPPHP to generate opcodes like PHP opcodes, then PHPPHP could become a serious alternative to PHP right?

Because without even having to compile PHPPHP to C (with HipHop for example), you could have equivalent performances if you cache the opcodes generated.

Now, I've read the README and looked at some parts of the code, but I'm not sure if this project generates any opcode (or if it executes directly the parsed code), and if yes then is the opcode compatible with the PHP opcodes?

And I confess I don't know the details of how Apache communicates with PHP (I know it can be a "module" of using fastCGI), but I guess this could be possible with PHPPHP.

That would be extremely interesting to have PHP developed in PHP, because following the latest discussions on PHP internals, there aren't enough PHP devs, and it is mostly because it is developed in C.

With PHPPHP, PHP users can participate to its development.

About the timeout

Hi
when i run the command

php composer.phar install --dev

there are some problems about that:

[Symfony\Component\Process\Exception\RuntimeException]
The process timed out.

I just run this
COMPOSER_PROCESS_TIMEOUT=4000 php composer.phar update

But the problem still exist .

I dont know WHY and HOW !!

Thanks.

composer install error

Hello!I perform composer install has been card after this command Then I added the debug composer - VVV install see error messages below Please help to solve it.
phpphp_error

$_GET/$_POST ?

I've been trying to get $_GET/$_POST support working for the entire day already, but I don't seem to be very lucky at this, unfortunately.

It definitely doesn't seem to be supported by default, so I tried to integrate it myself. I've tried the following approaches, without much luck. Would you guys be able to tell me what's up?

  • Add/Dump $_GET/$_POST in Executor.php's execute function, at the point where $scope->symbolTable is assigned.
  • Adding array's/Zval::ptrFactory's/Zval:factory's/Zval::<other stuff> to $this->symbolTable in ExecutorGlobals.php's __construct.
  • Dumping data in OpLines/FetchGlobalVariables.php's execute handler, to receive a notification of reading a global.
  • Some other stuff..

Other than that, I'm really amazed by how clean the PHP code is, very good job on that one! Hopefully globals will be supported soon.

Also, I noticed that var_dump($GLOBALS); results in an infinite loop.

Cheers,
Jurriaan

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.