troubleshooting Question

Script runs OK from browser but not from PHP CLI.

Avatar of rfresh
rfresh asked on
3 Comments1 Solution305 ViewsLast Modified:
My php script isn't connecting to the server and fetching weather reports when it's run from a cron jon. However, when I run the script from a browser it works fine and connects and fetches the weather report for a given airport. The script then parases it into an MySql table.

When the script runs from the cron job, the MySQL table is empty - indicating that it didn't fetch the weather data from

Can anyone see anything in my code below that would cause it to not work from the CLI yet work when run from a browser?
BTW - there is no html code in my script. I write debug data to a file so I know how the script ran. When I run the script from a browser the web page is blank.

$php_SQL = "TRUNCATE TABLE Metar_Reports_".$php_get_metar_report_filename."Z";
$php_resultID = mysql_query($php_SQL, $php_linkID);

$php_status = "Active";
$php_SQL = "SELECT DISTINCT airport FROM Metars WHERE status = '".$php_status."'";
$php_resultID = mysql_query($php_SQL, $php_linkID);
while ($php_row_metar_user_record = mysql_fetch_object($php_resultID))
        $php_icao = $php_row_metar_user_record->airport;
        $local_file = $php_row_metar_user_record->airport.".TXT";
        $ftp_server = "";
        $server_file = "/data/observations/metar/stations/$local_file";
        $ftp_user_name = "anonymous";
        $ftp_user_pass = "";
        $conn_id = ftp_connect($ftp_server);
        $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
        ftp_pasv ( $conn_id, true );
        if (ftp_get($conn_id, "Metar Reports/$local_file", $server_file, FTP_BINARY))
             $php_raw_metar_txt_filename = "/home/wxnotice/public_html/Metar Reports/".$local_file;
             $php_handle = fopen("$php_raw_metar_txt_filename","r");
             while (!feof($php_handle))
                     $php_line = fgets($php_handle, 4096);
                     if (StrLen($php_line) == 0)
                     if (StrLen($php_line) == 1)
                     if (substr($php_line,0,4) == $php_battcave_year)
                          $php_time = substr($php_line,11,5);
                          $php_line_year = substr($php_line,0,4);
                          $php_line_month = substr($php_line,5,2);
                          $php_line_day = substr($php_line,8,2);
                          $php_line_date = $php_line_year."-".$php_line_month."-".$php_line_day;

                      $php_wind = parse_for_wind($php_line, $Array_Wind, $php_output_handle);
                      $php_visibility =  parse_for_vis($php_line, $Array_Vis, $php_output_handle);
                      $php_ceiling = parse_for_ceil($php_line, $Array_Ceil, $php_output_handle);

                      $php_icao = substr($php_line,0,4);
                      $php_decoded_acao_report = get_icao_decoded($php_icao);

                      // active metars table is populated with raw and decoded metar reports
                      $php_SQL = "INSERT INTO Metar_Reports_".$php_get_metar_report_filename."Z SET report_date = '".$php_line_date."'".
                               ", report_time = '".$php_time."'".
                                      ", icao = '".$php_icao."'".
                                      ", wind = '".$php_wind."'".
                                ", visibility = '".$php_visibility."'".
                                   ", ceiling = '".$php_ceiling."'".
                                ", abrev_wind = '".LTrim($Array_Wind["metar_raw_wind_string"])."'".
                                 ", abrev_vis = '".LTrim($Array_Vis["metar_raw_vis_string"])."'".
                                ", abrev_ceil = '".LTrim($Array_Ceil["metar_raw_ceil_string"])."'".
                                    ", report = '".$php_line."'".
                                   ", decoded = '".$php_decoded_acao_report."'";
                      $php_resultID2 = mysql_query($php_SQL, $php_linkID);

Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros