Download the PHP package nacmartin/phpexecjs without Composer

On this page you can find all versions of the php package nacmartin/phpexecjs. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package phpexecjs

PhpExecJs

PhpExecJS lets you run JavaScript code from PHP.

Short example:

print_r($phpexecjs->evalJs("'red yellow blue'.split(' ')"));

Will print:

Array
(
    [0] => red
    [1] => yellow
    [2] => blue
)

Build Status Latest Stable Version Latest Unstable Version License

Installation

composer require nacmartin/phpexecjs

Sample program

Usage

Will print:

Array
(
    [0] => red
    [1] => yellow
    [2] => blue
)

Using contexts

You can set up a context, like libraries and whatnot, that you want to use in your eval'd code. This is used for instance by the ReactBundle to render React server-side.

For instance, we can compile CoffeeScript using this feature:

You can extend this example to do things like use this function as context:

That will print 9.

This can be used for instance, to use CoffeeScript or compile templates in JavaScript templating languages.

How it works

When you run evalJs, the code will be inserted into a small wrapper used to run JavaScript's eval() against your code and check the status for error handling.

If you set up a context, the code will be inserted before the call to eval() in JavaScript, and if you have the V8Js extension installed, it will precompile it.

Runtimes supported

By default, PhPExecjs will auto-detect the best runtime available. Currently, the routines supported are:

It is recommended to have V8Js installed, but you may want to have it installed in production and still be able to use PhpExecJs calling node as a subprocess during development, so you don't need to install the extension.

Adding a external runtime

If you have a external runner (let's say, Spidermonkey), and you want to use it, pass it to the constructor:

Contributing with runtimes

We would like to support more runtimes (Duktape, for instance). If you want to contribute with a runtime, it is pretty simple. You just have to implement src/Runtimes/RuntimeInterface. Check the directory src/Runtimes for examples.

Why can't I use some functions like setTimeout?

PhpExecJs provides a common denominator interface to JavaScript runtimes, so it can only run code that is agnostic about the interpreter. Thus, some features are disabled. Notably, timer functions are disabled because not all runtimes guarantee a full JavaScript event loop. If you want to use any of these please use directly node.js instead of this higher level library:

global, module, exports, require, console, setTimeout, setInterval, clearTimeout, clearInterval, setImmediate, clearImmediate

Credits

This library is inspired in ExecJs, A Ruby library.

The code used to manage processes and temporary files has been adapted from the Snappy library by KNP Labs.


All versions of phpexecjs with dependencies

PHP Build Version
Package Version
Requires symfony/process Version ~2.3|~3.0|^4.0|^5.0|^6.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package nacmartin/phpexecjs contains the following files

Loading the files please wait ....