Soap Not Found


#1

I’m trying to use the FlightAware API, however it doesn’t work. It just returns: Fatal error: require_once() [function.require]: Failed opening required ‘SOAP/Client.php’ (include_path=’.:/usr/lib/php:/usr/local/lib/php’)

I know that I have Soap installed because I used phpinfo() and cPanel to verify. I also know that the include path is set properly. Any help is appreciated. Thanks!


#2

That is a PHP installation/configuration issue, and is not specific to our API. Your hosting provider needs to ensure that all of the necessary files for SOAP-Client are actually present. It looks like they compiled PHP with that option, but didn’t actually install all of the files associated with it.


#3

I figured it out by manually moving some stuff around, however now I have this error: Warning: Invalid argument supplied for foreach()

Here’s the code it’s talking about:
$query = “idents SWA* in-air 0”;
$result = $soap->Search($query,15,0);
$flights = $result->aircraft;

foreach ($flights as $flight) {
$identity = $flight->ident;
$orig = $flight->origin;
$dest = $flight->destination;
$deptim = $flight->departureTime;
$arrtim = $flight->arrivalTime;
$atype = $flight->type;
mysqli_query($con,“INSERT INTO schedules(flightnum, depicao,arricao,aircraft,deptime,arrtime) VALUES($identity, $orig, $dest, $atype, $deptim, $arrtim)”);

$result2 = $soap->FlightInfo($identity."@".$deptim,1);
$routing = $result2->route;
$cruise = $result2->filed_altitude;
$time = $result2->filed_time;
mysqli_query($con,"UPDATE schedules SET route = $routing, flightlevel = $cruise, flighttime = $time WHERE flightnum = $identity");

}

I’m also not sure whether ident returns a tail number or flight number.


#4

The syntax should be:


$query = "-idents SWA* -inAir 0";

Until you get everything working, I recommend you view the raw response being returned by the server:


print_r($result);


#5

Thank you! There are no errors and the data seems to return properly, however it doesn’t go into the MySQL database (the database is being connected to).


#6

You probably want to quote and escape those arguments. php.net/mysqli.real-escape-string.php Alternatively use bound arguments in your query. But you are now asking questions that are unrelated to FlightXML and relate to general PHP development.


#7

Thanks for that. I’m not too worried about escapes because I have other security for that. Now I’ve figured out that the 2nd query to FlightAware isn’t working. It just returns this:

stdClass Object ( [next_offset] => 0 [flights] => Array ( ) ) stdClass Object ( [next_offset] => 0 [flights] => Array ( ) ) stdClass Object ( [next_offset] => 0 [flights] => Array ( ) ) stdClass Object ( [next_offset] => 0 [flights] => Array ( ) ) stdClass Object ( [next_offset] => 0 [flights] => Array ( ) ) stdClass Object ( [next_offset] => 0 [flights] => Array ( ) ) stdClass Object ( [next_offset] => 0 [flights] => Array ( ) ) stdClass Object ( [next_offset] => 0 [flights] => Array ( ) ) stdClass Object ( [next_offset] => 0 [flights] => Array ( ) ) stdClass Object ( [next_offset] => 0 [flights] => Array ( ) ) stdClass Object ( [next_offset] => 0 [flights] => Array ( ) ) stdClass Object ( [next_offset] => 0 [flights] => Array ( ) ) stdClass Object ( [next_offset] => 0 [flights] => Array ( ) ) stdClass Object ( [next_offset] => 0 [flights] => Array ( ) ) stdClass Object ( [next_offset] => 0 [flights] => Array ( ) )

Also, is there a way to find estimated time enroute and distance?


#8

The “Search” method does not return the estimated time enroute, however you can subsequently call “FlightInfoEx” (with the faFlightID returned by Search as the argument) and it will return the “filed_ete”.

The estimated distance is a little harder to determine. You could compute the “great circle” distance between the latitude/longitude of the origin and destination airports and get a pretty accurate number for longer flights. You could alternatively try using the “DecodeFlightRoute” method with the faFlightID and it will return a list of latitude/longitude of all of the points along the filed flight route, which you can compute the distance between each segment and add up the total. Be aware that DecodeFlightRoute is not able to decode all flight routes, particularly ones that are not entirely without the United States, so you may need to fall back on the great circle distance between simply the origin and destination.


#9

Alright thanks. And do you know about why FlightInfo doesn’t work?


#10

You must use FlightInfoEx, not FlightInfo. Also you can just pass the faFlightID, rather than ident@timestamp.


#11

Okay then how could I find the latitudes and longitudes for the origin and destination airports?


#12

AirportInfo will tell you details about any airport code, including its latitude and longitude. You can cache the results from this function in your database to avoid future lookups.

Once you have the latitude/longitude of both airports, you can calculate the great circle distance between them yourself (the math is not too difficult), or you can use the LatLongsToDistance method.


#13

Sorry to bother you so much with this and I really appreciate the help so far. The distance gets put into MySQL but the numbers are way off. No other data from FlightInfoEx gets put into MySQL. Here’s the code:


foreach ($flights as $flight) {
    $identity = $flight->ident;
    $flightid = $flight->faFlightID;
    $orig = $flight->origin;
    $dest = $flight->destination;
    $deptim2 = $flight->departureTime;
    $deptim = gmdate("H:i", $deptim2);
    $arrtim2 = $flight->arrivalTime;
    $arrtim = gmdate("H:i", $arrtim2);
    $atype = $flight->type;
    mysqli_query($con,"INSERT INTO phpvms_schedules(flightnum, depicao,arricao,aircraft,deptime,arrtime) VALUES('$identity', '$orig', '$dest', '$atype', '$deptim', '$arrtim')");
    
    $result3 = $soap->AirportInfo($orig);
    $result4 = $soap->AirportInfo($dest);
    $lat1 = $result3->latitude;
    $lat2 = $result4->latitude;
    $lon1 = $result3->longitude;
    $lon2 = $result4->latitude;
    $pi = 3.1415926;
    $rad = doubleval($pi/180.0);
    $lon1 = doubleval($lon1)*$rad; $lat1 = doubleval($lat1)*$rad;
    $lon2 = doubleval($lon2)*$rad; $lat2 = doubleval($lat2)*$rad;
    $theta = $lon2 - $lon1;
    $dist = acos(sin($lat1) * sin($lat2) + cos($lat1) * cos($lat2) * cos($theta));
    if ($dist < 0) { $dist += $pi; }
    $dist = $dist * 6371.2;
    $miles = doubleval($dist * 0.621);

    $result2 = $soap->FlightInfoEx($flightid,1,0);
    print_r($result2);
    $routing = $result2->route;
    $cruise = $result2->filed_altitude;
    $utime = $result2->filed_ete;
    mysqli_query($con,"UPDATE phpvms_schedules SET route = '$routing', flightlevel = '$cruise', distance = '$miles', flighttime = '$utime' WHERE flightnum = '$identity'");
    
}

By the way, when I run the script in my web browser… this happens:


#14

I recommend you try just using the LatLongsToDistance method and compare your output to that. If there is a significant difference, then your great circle implementation is defective.

If you’re not getting any output from the PHP page, try printing more output earlier or more frequently.


#15

Well, I’m not sure that’s the issue I’m trying to solve. The issue is that I don’t think soap is pulling the FlightInfoEx information and if it is then its not transferring to the variables for some freaking reason… and I just realized that I was using FlightXML v1. Well, now I’m back to this:


<?php

$con=mysqli_connect("localhost","protected","protected","protected");
// Check connection
if (mysqli_connect_errno($con))
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
  
$options = array(
                 'trace' => true,
                 'exceptions' => 0,
                 'login' => 'noooo',
                 'password' => 'dadoo',
                 );
$client = new SoapClient('http://flightxml.flightaware.com/soap/FlightXML2/wsdl', $options);

$query = "-idents UAL* -inAir 0";
$params = array("query" => $query,"howMany" => 15,"offset" => 0);
$flights = $client->Search($params);
            
foreach ($flights as $flight) {
    $identity = $flight->ident;
    $flightid = $flight->faFlightID;
    $orig = $flight->origin;
    $dest = $flight->destination;
    $deptim2 = $flight->departureTime;
    $deptim = gmdate("H:i", $deptim2);
    $arrtim2 = $flight->arrivalTime;
    $arrtim = gmdate("H:i", $arrtim2);
    $atype = $flight->type;
    mysqli_query($con,"INSERT INTO phpvms_schedules(flightnum, depicao,arricao,aircraft,deptime,arrtime) VALUES('$identity', '$orig', '$dest', '$atype', '$deptim', '$arrtim')");
    
    $result3 = $client->AirportInfo($orig);
    $result4 = $client->AirportInfo($dest);
    $lat1 = $result3->latitude;
    $lat2 = $result4->latitude;
    $lon1 = $result3->longitude;
    $lon2 = $result4->latitude;
    $theta = $lon1 - $lon2; 
    $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) +  cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta)); 
    $dist = acos($dist); 
    $dist = rad2deg($dist); 
    $dist = $dist * 69.11;

    $result2 = $client->FlightInfoEx($flightid,1,0);
    $routing = $result2->route;
    $cruise = $result2->filed_altitude;
    $utime = $result2->filed_ete;
    mysqli_query($con,"UPDATE phpvms_schedules SET route = '$routing', flightlevel = '$cruise', distance = '$dist', flighttime = '$utime' WHERE flightnum = '$identity'");
    
}

mysqli_close($con);

?> 

All that hard work at coding leads to this (nothing; nothing is going to the DB now):


#16

Can someone give me an example as to how to use the Search query in PHP?


#17

You need to try using print_r() more liberally when you have problems. You seem to be write long sections of code without checking that earlier parts are fully working. You might want to also do some error checking to ensure that you receive any results back too.


$result = $client->Search($params);
$flights = $result->SearchResult->aircraft;
foreach ($flights as $flight) {
...
}


#18

I’ve been trying to use print_r, but I don’t understand these stacks very well. Here’s the AirportInfo and FlightInfoEx dishing out errors for I have no clue why:

SoapFault Object ( [message:protected] => unknown airport INVALID [string:Exception:private] => [code:protected] => 0 [file:protected] => scripts/newschedules.php [line:protected] => 35 [trace:Exception:private] => Array ( [0] => Array ( [file] => scripts/newschedules.php [line] => 35 [function] => __call [class] => SoapClient [type] => -> [args] => Array ( [0] => AirportInfo [1] => Array ( [0] => KDEN ) ) ) [1] => Array ( [file] => scripts/newschedules.php [line] => 35 [function] => AirportInfo [class] => SoapClient [type] => -> [args] => Array ( [0] => KDEN ) ) ) [previous:Exception:private] => [faultstring] => unknown airport INVALID [faultcode] => CLIENT [detail] => stdClass Object ( [errorInfo] => stdClass Object ( [errorCode] => NONE ) ) ) SoapFault Object ( [message:protected] => Method invalid command name “domNode0x126018d0 domNode0x12601970 domNode0x126019c0” not found [string:Exception:private] => [code:protected] => 0 [file:protected] => scripts/newschedules.php [line:protected] => 48 [trace:Exception:private] => Array ( [0] => Array ( [file] => scripts/newschedules.php [line] => 48 [function] => __call [class] => SoapClient [type] => -> [args] => Array ( [0] => FlightInfoEx [1] => Array ( [0] => UAL1051-1376199357-airline-0155 [1] => 1 [2] => 0 ) ) ) [1] => Array ( [file] => scripts/newschedules.php [line] => 48 [function] => FlightInfoEx [class] => SoapClient [type] => -> [args] => Array ( [0] => UAL1051-1376199357-airline-0155 [1] => 1 [2] => 0 ) ) ) [previous:Exception:private] => [faultstring] => Method invalid command name “domNode0x126018d0 domNode0x12601970 domNode0x126019c0” not found [faultcode] => CLIENT [detail] => stdClass Object ( [errorInfo] => stdClass Object ( [errorCode] => Server UNKNOWN_METHOD {invalid command name “domNode0x126018d0 domNode0x12601970 domNode0x126019c0”} ) ) ) SoapFault Object ( [message:protected] => unknown airport INVALID [string:Exception:private] => [code:protected] => 0 [file:protected] => scripts/newschedules.php [line:protected] => 35 [trace:Exception:private] => Array ( [0] => Array ( [file] => scripts/newschedules.php [line] => 35 [function] => __call [class] => SoapClient [type] => -> [args] => Array ( [0] => AirportInfo [1] => Array ( [0] => KMSY ) ) ) [1] => Array ( [file] => scripts/newschedules.php [line] => 35 [function] => AirportInfo [class] => SoapClient [type] => -> [args] => Array ( [0] => KMSY ) ) ) [previous:Exception:private] => [faultstring] => unknown airport INVALID [faultcode] => CLIENT [detail] => stdClass Object ( [errorInfo] => stdClass Object ( [errorCode] => NONE ) ) ) SoapFault Object ( [message:protected] => Method invalid command name “domNode0x132f2ce0 domNode0x132f2d30 domNode0x132f2d80” not found [string:Exception:private] => [code:protected] => 0 [file:protected] => scripts/newschedules.php [line:protected] => 48 [trace:Exception:private] => Array ( [0] => Array ( [file] => scripts/newschedules.php [line] => 48 [function] => __call [class] => SoapClient [type] => -> [args] => Array ( [0] => FlightInfoEx [1] => Array ( [0] => UAL404-1376198532-airline-0083 [1] => 1 [2] => 0 ) ) ) [1] => Array ( [file] => scripts/newschedules.php [line] => 48 [function] => FlightInfoEx [class] => SoapClient [type] => -> [args] => Array ( [0] => UAL404-1376198532-airline-0083 [1] => 1 [2] => 0 ) ) ) [previous:Exception:private] => [faultstring] => Method invalid command name “domNode0x132f2ce0 domNode0x132f2d30 domNode0x132f2d80” not found [faultcode] => CLIENT [detail] => stdClass Object ( [errorInfo] => stdClass Object ( [errorCode] => Server UNKNOWN_METHOD {invalid command name “domNode0x132f2ce0 domNode0x132f2d30 domNode0x132f2d80”} ) ) ) SoapFault Object ( [message:protected] => unknown airport INVALID [string:Exception:private] => [code:protected] => 0 [file:protected] =>


#19

It’s hard for me to determine what arguments you were supplying since you are only pasting the response from the server.

However, from the server logs I can see that you were calling AirportInfo with no airport code as the argument (or were passing the argument incorrectly). Be sure you are specifying the argument name the same way it is specified in the documentation. It should be “airportCode”

I do not see any attempts by you to call FlightInfoEx in the server logs, so you are probably forming the request incorrectly to even be interpreted by the server.


#20

Well, that’s just the problem because I am supplying an airport code ($orig and $dest; and I’ve checked to make sure they are in fact airport codes). I’ve been looking for some more information as to how to use the FlightXML 2 API, but it’s just difficult to find anything. FlightInfoEx is being called: $result2 = $client->FlightInfoEx($flightid,1,0);