Calling CasperJS from PHP

Javascript coding ..

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 1
Joined: Mon Aug 14, 2017 12:24 am

Mon Aug 14, 2017 12:31 am

Here is a code snippet from my PHP code. I am trying to execute casperJS script by passing one argument to it. The output of CasperJS is expected in the variable $array_here. How to exactly debug whether my casperJS is able to execute it or not. It's Basically a Webhook[.PHP code] for a messenger Bot which on getting called runs a script -->scrapes data--->replies back.

I am new to CasperJS/PhantomJS framework and thus not able to debug/find out what exactly is happening in my shell_exec command.

If some one could put some light on how to find out whether CasperJS Script is able to run or not.

Initially I have tested the Script on my Windows CMD which runs totally fine and .PHP code on server which is able to interact with FB Messenger.

So Now I have put put all the codes in my CPanel,Uploaded the CasperJS,PhantomJS packages in my home directory and trying to rum them at one go. Like if I refresh this page : https://......../test.php

My directory Structure of Web Root(public) Directory of fileManager of CPanel :

Where I have Unzipped CasperJS and PhantomJS ?

What is the PHP code I am using to call Scripts:
$m= "flights";
//echo exec('/usr/bin/whoami');
echo shell_exec(/home/public_html/casperjs/bin/casperjs
/home/public_html/flights.js flights);

The commented echo works fine but the second one doesn't output anything.

Post Reply