从PHP执行PhantomJS

I'm trying to execute this command on my php script. shell_exec("phantomjs C:\sample\sample.js");

but it returns null, after just a few seconds. I was expecting that it should take long, since I already tested this command on cmd and it is working.

I am using ajax to call the controller that executes this script so that it can run in the background. the problem is the php side where it calls the exec / shell_exec command. Can anyone enlighten me?

Here is my code:

View.php

<a href="#" class="text-dark launch" id="<?php echo $row->id; ?>"> Launch</a>

ajax.js

$('.launch').on('click', function () {
    $.ajax({
        type: 'POST',
        url: 'http://localhost/sample/run_scrape',
        success: function (status) {
            console.log(status);
        }
    });
});

sample.php

 public function run() {

    $html = shell_exec("phantomjs C:\sample\scraper.js");
    echo json_encode($html);
}

scraper.js

var page = require('webpage').create();
page.open('https://detectmybrowser.com/', function(status){
    console.log("Status: " + status);   
    if(status === "success"){
        page.render('example.png');
    }
    phantom.exit();
});

Using absolute path for phantomjs worked for me

$html = shell_exec("C:\your_path_to_phantomjs_bin\phantomjs C:\sample\scraper.js");