Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2014
    Thanked 0 Times in 0 Posts

    Having issues running locally hosted PHP automatically

    Hey all, I'm a COMPLETE newcomer to coding and am having a big issue. It seems complicated (to me) so I'll try to lay it out so it's easy to understand.

    Basically, I'm using MAMP on Windows 7 to run a PHP script that calls NextBus for real-time bus data, which then is stored into a SQL database. When I start up the MAMP server and enter the PHP's address <http://localhost/php/getbuses.php>, it successfully populates the specified SQL database and columns.

    However, I need to run this code automatically every 2 minutes for a single 24 hour period, with the data going to the SQL database for every two-minute call. I learned that I need to create a cron job with Windows Task Scheduler that calls a .bat file that then calls the PHP file. So I created a file called cron.bat which has the following line of code in it:
    C:\MAMP\bin\php\php5.5.7\php.exe -f C:\MAMP\htdocs\php\getbuses.php
    After that, I created a schedule task in Windows Task Scheduler. I scheduled it to run the cron.bat file daily, and went into advanced options to make it run every X minutes.

    BUT I am having no luck getting it to work. The schedule task doesn't take place, and when I open cron.bat, I get a quick command prompt message flashed at me for a split second about "mysqli not being found" from line 26.

    Is there something really obvious that I'm missing? I made sure to have MAMP servers running, and still nothing.

    Also, just in case for reference, here is the body for the getbuses.php script (which again, works fine when I open it through MAMP):

    PHP Code:

        Gets NextBus location data for MBTA buses and saves it in a database.


    $data simplexml_load_file("http://webservices.nextbus.com/service/publicXMLFeed?command=vehicleLocations&a=mbta&t=0");
    $time round($data->lastTime['time']/1000);

    /* Connect to the MySQL database where the data will be stored.
            This assumes that there is a table named 'bus' with the following fields:
            vehicle (varchar)
            route (varchar)
            lat (float)
            lon (float)
            time (int)
    $host "localhost";
    $username "root";
    $password "root";
    $dbname "busdata";
    $mysqli = new mysqli$host$username$password$dbname );

    $data->vehicle as $veh){
    $query "INSERT INTO bus (vehicle,route,lat,lon,time) VALUES (".$veh['id'].",".$veh['routeTag'].",".$veh['lat'].",".$veh['lon'].",".($time $veh['secsSinceReport']).")";
    print_r(" ".($time $veh['secsSinceReport']));
    $result $mysqli->query$query );

    //$dayAgo = time()-86400;
        //$mysqli->query( "DELETE FROM bus WHERE time < $dayAgo" );

    (This question is also crossposted

  2. #2
    New to the CF scene
    Join Date
    May 2014
    Thanked 0 Times in 0 Posts
    Sorry, I forgot to add: Someone told me to enable mysqli in MAMP by going into php.ini and removing the " ; " before extension=php_mysqli


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts