paiza.io API unofficial wrapper. Using the Paiza API, compile and execute arbitrary code in a variety of programming languages.
This package use paiza.io API. So please read term of use (Japanese only).
composer require suzunone/code-runner
<?php
use Suzunone\CodeRunner\CodeRunner;
$source_code = 'console.log("Hello, world...");';
$CodeRunner = new CodeRunner;
$entity = $CodeRunner->create($source_code, CodeRunner::LANG_JAVASCRIPT);
while ($entity->is_running) {
$entity = $entity->status();
sleep(1);
}
var_dump($entity->details()->toArray());array(17) {
["id"]=>
string(22) ""
["language"]=>
string(10) "javascript"
["note"]=>
NULL
["status"]=>
string(9) "completed"
["build_stdout"]=>
NULL
["build_stderr"]=>
NULL
["build_exit_code"]=>
int(0)
["build_time"]=>
NULL
["build_memory"]=>
NULL
["build_result"]=>
NULL
["stdout"]=>
string(16) "Hello, world...
"
["stderr"]=>
string(0) ""
["exit_code"]=>
int(0)
["time"]=>
string(4) "0.07"
["memory"]=>
int(32408000)
["connections"]=>
int(0)
["result"]=>
string(7) "success"
C Language constant
C++ Language constant
Objective-C Language constant
Java Language constant
Kotlin Language constant
Scala Language constant
Swift Language constant
C# Language constant
GO Language constant
Haskell Language constant
Erlang Language constant
Perl Language constant
Python2 Language constant (string)
Python3 Language constant
Ruby Language constant
PHP Language constant
Bash Language constant
R Language constant
JavaScript Language constant
CoffeeScript Language constant
VB Language constant
Cobol Language constant
F# Language constant
D Language constant
Clojure Language constant
Elixir Language constant
MySQL Language constant
Rust Language constant
Scheme Language constant
Common Lisp Language constant
なでしこ Language constant
TypeScript Language constant
PlainText Language constant
is status already running.
is status already completed.
Start compiling and executing the program code.
CodeRunner::create(string $source_code, string $language, string $input = '', bool $longpoll = false, int $longpoll_timeout = 10): Suzunone\CodeRunner\Entities\OutputEntityInterface
| Parameter | Type | Description |
|---|---|---|
$source_code |
string | program code |
$language |
string | language constant |
$input |
string | string passed in standard input |
$longpoll |
bool | Wait for compilation and execution to complete. |
$longpoll_timeout |
int | longpoll timeout time. |
\Suzunone\CodeRunner\Entities\OutputEntityInterfaceReturns a template of the program code according to the language constants.
CodeRunner::getTemplate(string $language): string| Parameter | Type | Description |
|---|---|---|
$language |
string | language constant |
stringGet the program name according to the language constant.
CodeRunner::getLanguageName(string $language): string| Parameter | Type | Description |
|---|---|---|
$language |
string | language constant |
stringGet the program file extension according to the language constant.
CodeRunner::getLangExtension(string $language): string| Parameter | Type | Description |
|---|---|---|
$language |
string | language constant |
stringGet the API Key.
CodeRunner::getApiKey(): stringstringSet the API Key.
CodeRunner::setApiKey(string $api_key): void| Parameter | Type | Description |
|---|---|---|
$api_key |
string | API KEY |
stringGet the compilation and execution status of a program
OutputEntityInterface::status(): StatusEntity;
Suzunone\CodeRunner\Entities\Input|StatusEntityGet the results of compiling and executing a program.
OutputEntityInterface::details(): StatusEntity;
Suzunone\CodeRunner\Entities\Input|StatusEntityGet Response data.
getResponse() : ResponseElementInterfaceSuzunone\CodeRunner\Entities\Elements\Input|ResponseElementInterface| Properties | Type | Description |
|---|---|---|
| $id | string [readonly] | session id(This should be used in get_status/get_details API) |
| $status | string [readonly] | running', 'completed' |
| $error | string [readonly] | error message. |
| $is_error | bool [readonly] | if error is true |
| $is_completed | bool [readonly] | if completed is true |
| $is_running | bool [readonly] | if running is true |
| Properties | Type | Description |
|---|---|---|
| $id | string [readonly] | session id(This should be used in get_status/get_details API) |
| $status | string [readonly] | running', 'completed' |
| $is_error | bool [readonly] | if error is true |
| $is_completed | bool [readonly] | if completed is true |
| $is_running | bool [readonly] | if running is true |
| Properties | Type | Description |
|---|---|---|
| id | string | Session id |
| language | string | language |
| note | string | note |
| status | string | status('running', 'completed') |
| build_stdout | ?string | build output to stdout |
| build_stderr | ?string | build output to stderr |
| build_exit_code | int | build exit code |
| build_time | ?int | build time(second) |
| build_memory | ?int | build memory usage(bytes) |
| build_result | ?int | build result('success', 'failure', 'error') |
| stdout | ?string | code output to stdout |
| stderr | ?string | code output to stderr |
| exit_code | int | exit code |
| time | int | time to run(seconds) |
| memory | int | code memory usage(bytes) |
| result | string | code result('success', 'failure', 'error') |
| $is_completed | bool [readonly] | if completed is true |
| $is_running | bool [readonly] | if running is true |