Home » Php » run php code with javascript code using crontab in linux

run php code with javascript code using crontab in linux

Posted by: admin February 23, 2020 Leave a comment

Questions:

I am trying to a php code which contain JavaScript code using phantomjs and firefox browser into crontab. But it’s not working.If i run using CURL then it’s run but js code isn’t work.My crontab command below.

* * * * * /usr/local/bin/phantomjs http://XX.XX.XXX.XXX/project/index.php > /dev/null 2>&1

* * * * * /usr/bin/firefox http://XX.XX.XXX.XXX/project/index.php > /dev/null 2>&1

Someone tell me can i run php and js code into crontab?If yes then what is easier way?

How to&Answers:

As PhantomJS, which is a JavaScript based automation framework available for Windows, Mac OS X, Linux, other *ix systems.

Using PhantomJS, you can do things like this:

    console.log('Loading a web page');

    var page = new WebPage();
    var url = "http://www.phantomjs.org/";

    page.open(url, function (status) {
        // perform your task once the page is ready ...
        phantom.exit();
    });

Or evaluate a page’s title:

    var page = require('webpage').create();
    page.open(url, function (status) {
        var title = page.evaluate(function () {
            return document.title;
        });
        console.log('Page title is ' + title);
    });

Examples from PhantomJS’ Quickstart page. You can even render a page to a PNG, JPEG or PDF using the render() method.

so in your crontab

* * * * * /usr/local/bin/phantomjs /home/user/custom.js > /dev/null 2>&1