npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

exec-php

v0.0.6

Published

Execute PHP function within NodeJS application

Downloads

1,433

Readme

exec-php

Execute PHP function within NodeJS application

Installation

npm install exec-php

Usage

let execPhp = require('exec-php');

execPhp('path/to/file.php', '/usr/bin/php', (err, php, out) => {
    // the `php` argument is now contains all php defined functions
    php.my_func(arg1, arg2, (err, res, out, print) => {
        // `res` argument is now hold the returned value of `my_func` php function
        // `print` hold anything that get printed during calling the `my_func` function
    })
})

Arguments

  1. phpfile::string Path to user php file.
  2. phpbin::string Path to engine php binary file.
  3. callback::function A function to call after populating the php functions.

The callback function will be called with below arguments:

  1. error::mixed The error message.
  2. php::object The php object that hold all php defined functions.
  3. printed::string All printed string while populating php functions.

php Arguments

All user defined function on php engine will be appended to php argument of the caller. The function will be lower case. You can now call the function normally with additional last argument is the callback function to get response of the php functions call with below arguments:

  1. error::mixed Error message
  2. result::mixed Returned content of user php function
  3. output::string Printed string on requiring the php file.
  4. printed::string Printed string on calling user php function.

Example

// file.php
<?php

echo "One";
function my_function($arg1, $arg2){
    echo "Two";
    return $arg1 + $arg2;
}
// app.js
let execPhp = require('exec-php');

execPhp('file.php', (err, php, out) => {
    // outprint is now `One'.

    php.my_function(1, 2, (err, result, output, printed) => {
        // result is now `3'
        // output is now `One'.
        // printed is now `Two'.
    })
})

Note

All uppercase function name on PHP will be converted to lowercase on exec-php.

// file.php
<?php

function MyFunction($a, $b){
    return $a + $b;
}
// app.js
let execPhp = require('exec-php')

execPhp('file.php', (err, php, out) => {
    php.myfunction(1, 2, function(error, result){
        // result is now 3
    })
})

ChangeLog

  1. 0.0.3
    1. Handle PHP throw error exception
  2. 0.0.4
    1. Upgrade tmp module to suppress opsolete functions ( GuilhermeReda )
    2. Add noop function to support the new node callback standard
  3. 0.0.5
    1. Close temp file pointer on removing the file ( MHDMAM )
  4. 0.0.6
    1. Remove deprecated module.parent ( Jakub Zasański )
    2. Upgrade deprecated dependencies