PHP Having issues running locally hosted PHP automatically
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Having issues running locally hosted PHP automatically

Hybrid View

  1. #1
    Join Date
    May 2014
    Posts
    1

    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:
    Code:
    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: "."

    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:
    <?php
        
    /* 

        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 );
        

        foreach(
    $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" );
    ?>
    THANKS A TON!

    (Also cross-posted in:
    CodingForums.com/mysql
    http://www.dreamincode.net/forums/forum/159-mysql/)

  2. #2
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster
    Join Date
    May 2002
    Posts
    10,860

    Re: Having issues running locally hosted PHP automatically

    Have you tried putting "pause" at the end of the .bat file to see what the output is?
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center