Viewed   117 times

I want to execute PhantomJS from PHP on localhost.

Can any body explain how to execute PhantomJS from PHP and what package I should download from phantomjs.org?

 Answers

2
  • download the PhantomJS binary, upload it somewhere and make it executable (chmod +x)
  • if you are going to make screenshots, setup fontconfig (this is pretty specific to my config but the goal is to make sure to have at least some fonts on your system)
  • run the following in PHP:
    $response = exec('/path/to/phantomjs myscript.js');
Saturday, December 24, 2022
5

You can use AJAX to display the output from the query in the input field.

Step 1: Add this line of code to the bottom of getrowcount.php:

echo $test;

Step 2: Amend your HTML so that it looks like this:

<form id="get">
   <input type="text" id="pin" name="pin" class="form-control" readonly>
   <input type="submit" class="btn btn-primary" value="Generate ID">
</form>

Step 3: Add this script to the bottom of the page.

<script>
$(document).ready(function(){
    $("form#get").submit(function(event) {
        event.preventDefault();
        var input = $("#pin");

        $.ajax({
            type: "POST",
            url: "getrowcount.php",
            success: function(data) { input.val(data); }
        });
    });
});
</script>
Friday, October 28, 2022
 
griffin
 
1

The numeric date time your are referring to is called a timestamp. It is the number of seconds elapsed since january 1st of 1970 if i'm not wrong.

To send a date to javascript, just print it out using the timestamp x 1000 since it also accepts millisecond initialization format:

mydate = new Date(<?php echo $mytimestamp*1000; ?>);

Good luck

Thursday, November 24, 2022
 
2

Because computers can't represent floating numbers properly. It's probably 53.95400000000009 or something like that. The way to deal with this is multiply by 100, round, then divide by 100 so the computer is only dealing with whole numbers.

var start = 53.955,
        res1,
        res2;
    
    res1 = start.toFixed(2);
    res2 = (start * 100).toFixed(0) / 100;
    console.log(res1, res2);
//Outputs
"53.95"
53.96
Thursday, September 1, 2022
 
2

Another one of my own questions answered by myself I am happy that I am starting to understand this new Hobby :) well any way luckily I am using virtual box whilst developing my server to my needs and every time I complete a task like install Zpanel configure it I create a clone.

so what I done is I reverted back to my server set up before the PhantomJS and CasperJS. I then installed both PhantomJS and CasperJS using the following methods and then used my test.php script to test server functionality

Okay I used the following to install PhantomJS

# wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.7-linux-i686.tar.bz2
# tar xvf phantomjs-1.9.1-linux-i686.tar.bz2
# cp phantomjs-1.9.1-linux-i686/bin/phantomjs /usr/local/bin

Then I use these Commands For CasperJS install

# cd /opt
# wget https://codeload.github.com/n1k0/casperjs/legacy.zip/1.1-beta3
# unzip 1.1-beta3
# ln -s n1k0-casperjs-4f105a9/ casperjs
# ln -s /opt/casperjs/bin/casperjs /usr/local/bin/

I then created this on my server

PHP Test File Test.php

<?php
    ## This Function Below Sets PhantomJs So CasperJS Can Use It
    putenv("PHANTOMJS_EXECUTABLE=/usr/local/bin/phantomjs");
    echo "Running PhantomJS version: ";
    echo exec('/usr/local/bin/phantomjs --version 2>&1');
    echo "<br />";
    echo "Running CasperJS version: ";
    echo exec('/usr/local/bin/casperjs --version 2>&1');

?>

After this I ran Test.php And got this result

Running PhantomJS version: 1.9.7
Running CasperJS version: 1.1.0-beta3

My Server Now Runs CasperJs With PhantomJS

Please Uprate This Answer if you like it :)

Friday, November 4, 2022
 
taleb
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :