Asked  8 Months ago    Answers:  5   Viewed   35 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

81
  • 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');
Wednesday, March 31, 2021
 
julesj
answered 8 Months ago
81

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>
Wednesday, March 31, 2021
 
rlanvin
answered 8 Months ago
12

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
Wednesday, March 31, 2021
 
DCD
answered 8 Months ago
DCD
16

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 :)

Wednesday, August 4, 2021
 
Timur Mustafaev
answered 3 Months ago
46

There are a number of ways to not run a particular test - putting it into a blacklist so it's never run may not be the way - as changing it means editing the blacklist, and you'll often endup bouncing it in and out of version control.

There are several other ways that may be more appropriate:

If a test is not yet ready to run:

$this->markTestIncomplete('This test has not been implemented yet.');

If there's an outside reason it should not be run, skip it:

if (!extension_loaded('mysqli')) {
    $this->markTestSkipped('The MySQLi extension is not available.');
}

You can also put that into the setUp() function, so it will skip all the tests in a test-class.

You can make a test dependant on a previous one succeeding:

public function testEmpty()
{
    $stack = array();
    $this->assertTrue(empty($stack));
    return $stack;   // also sends this variable to any following tests - if this worked
}
/**
 * only runs if testEmpty() passed
 *
 * @depends testEmpty
 */
public function testPush(array $stack)
{
}

The @group -name- annotation is one of the best ways to specifically stop, or run one group of tests

/**
 * @group database
 * @group remoteTasks
 */
public function testSomething()
{
}

testSomething() is now in two groups, and if either is added on the command line (or in the config.xml) --exclude-group parameter. it won't be run. Likewise, you could run only tests that belong to a particular group - say named after a feature, or bug report.

Wednesday, September 8, 2021
 
TomasThall
answered 2 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share