0

I have a php web app and have written a class that effectively invokes an API which requests data from our 3rd party membership system database. The API returns the data and saves the XML into a file (as it's a very large data set). This xml file is then parsed and I upload some of that data into my web application's database.

It takes approximately 4 hours for the API to return all of the data. Currently I invoke this process by clicking a button on my web page. However, I want to automate the process and schedule it to run every so often but have no idea where to begin or what to even Google. The web app runs on a Windows server which is running xammp. Any help is much appreciated.

I have managed to create a .bat file to execute my php script but I now get several errors in the CMD windows stating that it failed to open any of the files that I include in my script file:

My script file is:

<?php

include '../config.php';
include (ROOT.'/includes/my_session.php');
include (ROOT.'/model/dao.php');
include (ROOT.'/model/miller_api.php');
include (ROOT.'/model/branch_db.php');

$a = new miller_api;

$k = $a->apiRequest('key');
$a->apiRequest('branch', $k);

And here is a screen shot of the errors I am getting: CMD errors

Lee A
  • 45
  • 1
  • 9
  • 1
    you can use a "Task scheduled" also knowed as "cron job" in linux. You can read more here https://stackoverflow.com/questions/9894804/use-php-to-set-cron-jobs-in-windows – juanbits Aug 17 '18 at 20:45
  • Create cron for that – Brijesh Dubey Aug 18 '18 at 03:03
  • Possible duplicate of [Run a task every x-minutes with Windows Task Scheduler](https://stackoverflow.com/questions/4249542/run-a-task-every-x-minutes-with-windows-task-scheduler) – Alessandro Da Rugna Aug 18 '18 at 07:07

1 Answers1

0

It is quite simple. Create a run.bat file with the following command

C:\xampp\php\php.exe C:\xampp\htdocs\SCRIPTFOLDER\SCRIPT.php

And schedule the run.bat file using windows Task Scheduler

https://www.techsupportalert.com/content/how-schedule-programs-run-automatically-windows-7.htm

Rinsad Ahmed
  • 1,877
  • 1
  • 10
  • 28
  • Thanks you. I created my .ba file as described above and this works in so far as php is being executed BUT I have a number of files I include in my initial php file and I get error messages in the CMD window stating that it failed to open them. Do I need to effectively merge all of these files into 1 big script in order for this to work? – Lee A Aug 20 '18 at 09:18
  • When including files you should use include(dirname(__FILE__)."/xxx.php"); format. Otherwise, it will search from the place where the batch file is located and it won't work. Or put your batch file in the same place as initial php and it will work – Rinsad Ahmed Aug 23 '18 at 00:52
  • Thanks Sinead. Makes perfect sense – Lee A Aug 23 '18 at 08:46