CasperJS from Php

4,115 views
Skip to first unread message

Killwil

unread,
Nov 13, 2012, 3:44:05 AM11/13/12
to casp...@googlegroups.com
Hello I try to execute this PHP code :
assuming /usr/local/bin/casperjs /scripts/test.js works and exports PHANTOMJS_EXECUTABLE like : 
export PHANTOMJS_EXECUTABLE="/usr/local/bin/phantomjs"

echo shell_exec("/usr/local/bin/casperjs /scripts/test.js");

and this is the result :

Fatal: [Errno 2] No such file or directory; did you install phantomjs? 

Could someone help me on this issue ?

Killwil

unread,
Nov 13, 2012, 4:15:36 AM11/13/12
to casp...@googlegroups.com
I removed the error by adding the following line on the top of the PHP file :

putenv("PHANTOMJS_EXECUTABLE=/usr/local/bin/phantomjs");

but now, my test.js produce anything.

var casper = require('casper').create();
casper.start();
casper.then(
function(){
this.echo("test");
});
casper.run();

???

Killwil

unread,
Nov 13, 2012, 4:26:25 AM11/13/12
to casp...@googlegroups.com
Well...

It works on PHP CLI...
But not when calling from web browser (localhost/test.php)
Don't know why...

Killwil

unread,
Nov 13, 2012, 6:24:29 AM11/13/12
to casp...@googlegroups.com
OK... 3 hours :(

On Mac OSX 10.8 (not sur it works on Ubuntu for example)

PHP file that works like a charm...


putenv("PHANTOMJS_EXECUTABLE=/usr/local/bin/phantomjs");
putenv("DYLD_LIBRARY_PATH");

echo shell_exec("/usr/local/bin/casperjs ./test.js 2>&1");


Kévin RICHARD

unread,
Sep 7, 2013, 11:34:09 AM9/7/13
to casp...@googlegroups.com
Thanks man ! I almost pulled out my hair !

trippy....@gmail.com

unread,
Aug 14, 2017, 5:43:16 AM8/14/17
to CasperJS
@Kevin . I am stuck at the same problem can you please help.

Ken Soh

unread,
Aug 15, 2017, 5:58:58 PM8/15/17
to CasperJS

I've just replied to another user below info, whether php.ini has been updated in order to allow running commands on shell.

---

For me I set it this way. But exec only outputs the last line need to provide array parameter - http://php.net/manual/en/function.exec.php

Also, by default PHP don't allow running commands (shell_exec, exec and others) on shell it is security breach. You have to update php.ini to override this - https://www.namecheap.com/support/knowledgebase/article.aspx/9396/2219/how-to-enable-exec

$exec_result = exec("PHANTOMJS_EXECUTABLE=/usr/local/bin/phantomjs /usr/local/bin/casperjs /full_path/deliveroo.js " . $_GET['POSTAL']);

then echo $exec_result etc..

Reply all
Reply to author
Forward
0 new messages