PHPackages                             eminmuhammadi/phpcompiler - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. eminmuhammadi/phpcompiler

ActiveProject[Utility &amp; Helpers](/categories/utility)

eminmuhammadi/phpcompiler
=========================

The basic PHP Compiler for Python , Cpp , Java , C11 , C

933[1 PRs](https://github.com/eminmuhammadi/phpCompiler/pulls)JavaScript

Since Jul 5Pushed 4y ago1 watchersCompare

[ Source](https://github.com/eminmuhammadi/phpCompiler)[ Packagist](https://packagist.org/packages/eminmuhammadi/phpcompiler)[ RSS](/packages/eminmuhammadi-phpcompiler/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (2)Used By (0)

phpCompiler
===========

[](#phpcompiler)

The basic PHP Compiler for Python , Cpp , Java , C11 ,C

```
git clone https://github.com/eminmuhammadi/phpCompiler.git
```

 [![](/docs/screen.png)](/docs/screen.png)

Getting Started
---------------

[](#getting-started)

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

### Prerequisites

[](#prerequisites)

What things you need to install the software and how to install them

```
apt-get install g++
```

```
apt-get install gcc
```

```
apt-get install clang
```

```
apt-get install javac
```

```
apt-get install python
```

LanguagesCommand1C++`apt-get install g++`2C11`apt-get install clang`3C`apt-get install gcc`4Python`apt-get install python`5Java`apt-get install javac`### Installing

[](#installing)

Main source code is located in `src/phpCompiler.php`. For using this class in project you need to set up:

```
require_once 'vendor/autoload.php';
```

and Create new class using `eminmuhammadi\phpCompiler() `

```
$COMPILER = new eminmuhammadi\phpCompiler();
```

### Testing

[](#testing)

After installing recomended to run Test service in `test/testAll.php`

#### Declare variables

[](#declare-variables)

VariableCommand1`command`root software2`executable`runner3`runFile`run file4`time`time for running5`code`main code6`input`input for code7`fnCode`code file name8`fnInput`input file name9`fnError`error file name```
  $env = [
   'command'    => 'g++ -std=c++11',
   'executable' => 'a.out',
   'runFile'    => './a.out' , //out
   'time'       => '1', //seconds
   'code'       => $_POST['code'] ,
   'input'      => $_POST['input'],
   'fnCode'     => 'main.cpp',
   'fnInput'    => 'input.txt',
   'fnError'    => 'error.txt'
  ];
```

`time` makes executation against to looping

#### Set time for executation (Attention)

[](#set-time-for-executation-attention)

```
  $COMPILER->setTimeOut($time);
```

This rule make php file against to looping.

Run &amp; Create JSON Service
-----------------------------

[](#run--create-json-service)

Collect all datas for compile procession.

```
  $RESULT = $COMPILER->Run(
                 $env['command'],
                 $env['time'],
                 $env['executable'],
                 $env['runFile'],
                 $env['code'],
                 $env['input'],
                 $env['fnCode'],
                 $env['fnInput'],
                 $env['fnError']
               );
```

That's all and we need to create application service a json type.

```
  header('Content-Type: application/json');

  $data = [
    'code'       => $env['code'] ,
    'time_limit' => $time,
    'input'      => $env['input'],
    'result'     => $RESULT
  ];

  echo json_encode($data,JSON_PRETTY_PRINT);
```

JSON shows like :

```
{
    "code": "      #include \r\n      #include \r\n      using namespace std;\r\n\r\n      int main()\r\n      {\r\n\r\n        cout
