1

I want to run this my script using task scheduler on Windows Server. This script contains PHP, HTML, and Javascript. This script is using for Image Recognition and should running daily.

If I'm using browser and type this url bellow

http://localhost/html/xpix/index.php?APICall=1&APICGI=1&APICode=0x00000008&APIFile=2017-11-02_08-00&DateToCompare=2017-11-02&DateToProcess=2017-11-02&ObjRecogMode=1&CheatMode=1

its working fine.

But while on CLI (Windows Command Prompt) and using curl, I've tried this bellow

curl "http://localhost/html/xpix/index.php?APICall=1&APICGI=1&APICode=0x00000008&APIFile=2017-11-02_08-00&DateToCompare=2017-11-02&DateToProcess=2017-11-02&ObjRecogMode=1&CheatMode=1"

It won't work even tried using -s parameter. Its just print the HTML Code.

I've tried to use Google Chrome headless but still won't work

chrome.exe --headless --disable-gpu --remote-debuging-port=9222 "http://localhost/html/xpix/index.php?APICall=1&APICGI=1&APICode=0x00000004&APIFile=2017-11-02_08-00&DateToCompare=2017-11-01&DateToProcess=2017-11-01&ObjRecogMode=1&CheatMode=1"

This script also contains an Ajax and do call Java Web Service and save data to MySQL Database.

Is there any miss configuration?

Yohanim
  • 3,319
  • 9
  • 52
  • 92
  • It won't work. `curl` can't execute `javascript`, even `html`. It will just read it as string. You should call the `Java Web Service` directly. – Dharma Saputra Nov 30 '17 at 08:01
  • how about using a `php -f`? it is just a same things? – Yohanim Nov 30 '17 at 08:03
  • Yes. You said that you call `Java Web Service` via AJAX, which means it's javascript. The only thing to run javascript is run it via it's engine (browser, nodejs, phantomjs). I think you should change the way of your cronjob works. – Dharma Saputra Nov 30 '17 at 08:08

2 Answers2

0

CURL won't load any javascript code, cURL get only html code. You should use something like PhantomJS to get full results from your index.php page with ajax calls and JS results.

Here you have an example howto use PhantomJS: http://phantomjs.org/api/webpage/property/content.html

Krzysztof Raciniewski
  • 4,735
  • 3
  • 21
  • 42
  • how about using `php -f`? its just a same things? – Yohanim Nov 30 '17 at 08:05
  • Exactly, if you want to run phantomjs from PHP script, you can use this: https://github.com/jonnnnyw/php-phantomjs. More information about running phantomjs from PHP code you can read here: https://stackoverflow.com/questions/20202407/how-to-execute-phantomjs-from-php – Krzysztof Raciniewski Nov 30 '17 at 08:13
0

You are missing something important here. When you make the request from the browser the browser then renders the page and runs the Javascript which makes the AJAX call.

When you make the request from curl you make a pure HTTP request and return pure text of the HTML document. This means there won't be any rendering because there is no browser which means no Javascript will run which results in no Ajax script running.

I suggest you do one of the following:

  • Use headless chrome to make the request (read more here)
  • Make the request straight to the AJAX url.
  • Write a Python script with Selenium (read more here)
Bubble Hacker
  • 6,425
  • 1
  • 17
  • 24