PHP Classes

File: PHPNodeJSExample.php

Recommend this page to a friend!
  Classes of Dean Gostiša   PHP Node.js   PHPNodeJSExample.php   Download  
File: PHPNodeJSExample.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Node.js
Execute JavaScript using Node.js from PHP
Author: By
Last change: Update of PHPNodeJSExample.php
Date: 9 months ago
Size: 780 bytes
 

Contents

Class file image Download
<?php

include_once dirname(__FILE__) . '/PHPNodeJS.php';

$debug = true;
$PHPNodeJS = new PHPNodeJS($debug);

// example 1 (run simple script without function)
$PHPNodeJS->run('
    var var1 = 10;
    var var2 = 20;
    console.log(var1+var2);'
);

// example 2 (run simple script, supply multiple arguments to function you want to call)
$PHPNodeJS->run('
    function test(var1, var2) {
        if (var1 == "3" && var2 == "20") {
            return true;
        } else {
            return false;
        }
    }'
, 'test', array('3', '20'));

// example 3 (run script that uses jQuery as dependcy)
echo $PHPNodeJS->run('function test(url) {
  jQuery.get(url, function(data) {
        console.log(data);
    });
        return "";
}'
, 'test', array('http://www.videodeck.net'), true);
?>