Download the PHP package lifespikes/php-node without Composer
On this page you can find all versions of the php package lifespikes/php-node. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lifespikes/php-node
More information about lifespikes/php-node
Files in lifespikes/php-node
Package php-node
Short Description Spawn and manage node instances from PHP
License MIT
Informations about the package php-node
PHP Node
Simple library for executing short-lived NodeJS processes from PHP.
Hi Packagist :) https://packagist.com/orgs/lifespikes/packages/3021975
Who is this for?
Every language and platform has their pros and cons, for us one of the biggest benefits of JavaScript is being able to whip up programs in the span of a few minutes.
This package is for developers who want a simple, object-oriented, library to integrate microservices written in Node in their PHP apps.
All this for a process manager?
PHP Node is a library we built to leverage power from multiple languages different members of our team specialize in and their awesome ecosystems. Naturally we want these integrations to be as seamless as possible with the rest of our code, but we also don't want to make anything more complicated than it needs to be.
Instead of implementing separate APIs for each service using let's say a SOAP or REST interface using Express, or deploying these services as docker containers, PHP Node helps us:
- Execute scripts using a simple one-line syntax
- Mitigate disconnects in error reporting
- Quickly deploy new microservices with minimal setup
- Test integrations by asserting
FinishedProcess
properties - Send and receive information without using arguments
- Easily determine error reasons, exit status, and other details
Examples
Using PHP Node is pretty straight forward.
The very first step is going to be making sure you have NodeJS installed on your
machine. The version you run is up to you. Then, make sure the path to Node is present
in your PATH
, or set as a NODE_BINARY
environment variable.
Now make sure your script is accessible by your web server or PHP process owner.
Lastly, make sure to expect input on your script by receiving it using stdin
, instead
of argv
. We opted for using the stream route to allow us to broadcast reliable and larger
chunks of data.
(This library is pretty awesome at this: https://www.npmjs.com/package/get-stdin)
Then, just run it. In this example we're using a microservice to take a screenshot of a website:
For context, we'll write another small pseudo-script: