Z
Z
ZaurK2017-08-31 16:14:43
PHP
ZaurK, 2017-08-31 16:14:43

Why can't I run casperjs from php?

The second day I'm scratching my head, please help me figure it out. The task is to run casperjs not through the console, but through a php script. What I've done? I copied the phantomjs, casperjs and python downloaded from the official sites to the C drive, registered the path C: / casperjs / bin; C: / phantomjs / bin; C /: Python27 in the Path variable, separated by a semicolon. I initiated git in the project folder and checked the versions of casperjs and phantomjs in its console, everything shows fine. Moreover, I can run a test file for Casper, it works and even gives screenshots from the screen.
But I'm stuck on the problem of how to run Casper from a php file ... it just doesn't show anything. Here are my files

error_reporting(E_ALL);
$start = microtime(true);
echo date("H:i:s");

function parser() {
        try {
      putenv("PHANTOMJS_EXECUTABLE=/usr/local/bin/phantomjs");
      putenv("DYLD_LIBRARY_PATH");
            echo(shell_exec('casperjs test.js '));
            flush();
        } catch (Exception $exc) {
            echo('Error!');
            echo $exc->getTraceAsString();
        }
    }

parser();

//////////////////////////////////////////////////////////////////////////
$time = microtime(true) - $start;
printf("<br>".date('H:i:s').' Готово! Процесс выполнялся %.4F сек.', $time);

var casper = require('casper').create();

casper.start('http://casperjs.org/', function() {
    this.echo(this.getTitle());
});

casper.thenOpen('http://phantomjs.org', function() {
    this.echo(this.getTitle());
});

casper.run();

As a result, I get:
15:07:56
15:07:56 Done! The process ran for 0.1046 sec.
Maybe I didn’t do something in the settings, maybe I need to put some kind of symlink, help me figure it out.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question