0

I tried many online methods people have suggested and still not reached a solution

i need to run a php file that contain javascript from cronjob

For now, I can not do it through PHP

If anyone has an idea I'd love to read

Swissa Yaakov
  • 186
  • 3
  • 15
  • what can javascript do in a cronjob ? Send an ajax request back to tghe server – exussum Nov 08 '13 at 09:10
  • Can you run that script in shell, without providing any input to it interactively? If yes, then with appropriate settings you can use cron, else not. – Anshul Goyal Nov 08 '13 at 17:59

2 Answers2

0

You will probably have to trigger it through a browser. Get a computer to open the URL via the cron tab (or some other timed device... I know you can do it through Automator/AppleScript on a Mac).

Dan Goodspeed
  • 3,484
  • 4
  • 26
  • 35
0

How I do it: I split the job in to tasks.

Task 1: Execute Javascript

Javascript would require a browser to run. In this respect you can try casperjs/phantomjs. You can create a a cronjob for this easily. Please check: Running a casper.js script from cron

Task 2: Deliver results to PHP

I assume that you take the results of the JS and use it in the PHP. So JSON can do the job. At the end of the first task output to a file. In this task, read it using file_get_contents.

Task 3: PHP Cron

It is obvious :)

Sure that there are better, easier and simpler solutions. I am a newbie also here, but this method all my problems for a similar work.

Community
  • 1
  • 1