AirNav Systems Forum
AirNav RadarBox and RadarBox24.com => AirNav RadarBox and RadarBox24.com Discussion => Topic started by: asiawatcher on December 02, 2008, 03:03:21 PM
-
anyone can give me a php example of how to connect to radarbox and relay its data to my website through php ?
cheers
-
Asiawatcher, as a start here is an example of how to relay the port 30003 data output by RadarBox on to a webpage using php. I'm assuming that you are familiar with php, have it installed and have a service such as Microsoft's Internet Information Services installed and activated so that you can load and test local php files.
Start by creating a file testport.php on your 'localhost' directory (e.g. C:\Inetpub\wwwroot ) with the contents..
<html>
<body>
<?php
$fp = fsockopen('localhost', 30003, $errno, $errstr);
if (!$fp)
{
echo "$errstr ($errno)<br />\n";
}
else
{
$out = "GET / HTTP/1.1\r\n";
$out .= "Host: localhost\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
while (!feof($fp))
{
echo fgets($fp, 128);
}
fclose($fp);
}
?>
</body>
</html>
Then, with RadarBox running, if you fire up your browser and type http://localhost/testport.php (http://localhost/testport.php) into the address box you should see the port 30003 data relayed on to your webpage.
The trouble then is that after a default of 30 seconds you get a message like "Maximum time exceeded". This is because php scripts are only designed to run for the maximum time specified by "max_execution_time" in your php.ini which you can change (if you change this you will need to reboot). You will still run out of time eventually though so maybe you can look into auto-refreshing the page using a meta tag. Eg. to refresh after 25 seconds add:
<META HTTP-EQUIV="REFRESH" CONTENT="25">
This all works with RadarBox 2009 and Php 5 using WindowsXP Professional and IIS as a webpage publishing service.
-
hi thanks for your post in http://www.airnavsystems.com/forum/index.php?topic=1756.new;topicseen
i get lots of raw data of the form
MSG,1,0,0,3412C8,0,2008/12/03,14:22:43.472,2008/12/03,14:27:43.472,AEA1451,39000,465,112,37.3313,22.7358,0,,0,0,0,0 MSG,3,0,0,3A4586,0,2008/12/03,14:22:43.472,2008/12/03,14:27:43.472,MEA236,35025,457,108,37.6098,22.5621,0,,0,0,0,0 MSG,3,0,0,3420CF,0,2008/12/03,14:22:50.081,2008/12/03,14:27:50.081,IBE38RE,15300,369,086,37.7688,23.7292,-960,,0,0,0,0 MSG,3,0,0,4B168F,0,2008/12/03,14:22:50.091,2008/12/03,14:27:50.091,SWR838A,07425,285,104,38.0794,23.9963,-1408,,0,0,0,0 MSG,3,0,0,3C64FA,0,2008/12/03,14:22:52.435,2008/12/03,14:27:52.435,DLH592,36975,455,140,37.9497,23.7401,0,,0,0,0,0 MSG,3,0,0,505CE5,0,2008/12/03,14:22:52.445,2008/12/03,14:27:52.445,ESK8ED,20625,397,335,38.2043,24.2479,3136,,0,0,0,0 MSG,3,0,0,3A4586,0,2008/12/03,14:22:54.818,2008/12/03,14:27:54.818,MEA236,35025,458,108,37.6026,22.5892,0,,0,0,0,0 MSG,3,0,0,3420CF,0,2008/12/03,14:23:00.797,2008/12/03,14:28:00.797,IBE38RE,15150,369,086,37.7699,23.7526,-960,,0,0,0,0 MSG,3,0,0,505CE5,0,2008/12/03,14:23:02.019,2008/12/03,14:28:02.019,ESK8ED,21050,400,336,38.2191,24.2394,2944,,0,0,0,0 MSG,3,0,0,3C64FA,0,2008/12/03,14:23:02.019,2008/12/03,14:28:02.019,DLH592,36975,455,140,37.9351,23.7556,0,,0,0,0,0 MSG,3,0,0,3412C8,0,2008/12/03,14:23:04.382,2008/12/03,14:28:04.382,AEA1451,39000,465,112,37.3030,22.8202,0,,0,0,0,0 MSG,3,0,0,3A4586,0,2008/12/03,14:23:05.554,2008/12/03,14:28:05.554,MEA236,35000,458,108,37.5948,22.6186,0,,0,0,0,0 MSG,3,0,0,3420CF,0,2008/12/03,14:23:10.441,2008/12/03,14:28:10.441,IBE38RE,15000,368,087,37.7708,23.7723,-960,,0,0,0,0
any idea how i can structure them ? like make them being displayed on tables ? i want to make a flight display like the one on radarbox only display flags flights etc without radar
thanks a lot man
-
Yes, that's what I get too.
I don't know what you want to display, you'll have to extract the fields you want to display from the line, each field is separated with a comma. If you want to display flight numbers in a table for example then you will have to extract the flight number from each line and put it in a variable called say $flightNumber then in your html you can do something like this for each MSG line to produce a line of the table
<TR><TD><?php echo $flightNumber; ?></TD></TR>
I think what you probably want to do is to build up a table of flight numbers without repetitions. In which case you are going to have to create an array of the flight numbers first and then display the elements of the array like this...
<TABLE>
<?php
$count = count($array);
for ($i = 0; $i < $count; $i++)
{
echo '<TR><TD>' . $array[$i] . '</TD></TR>';
}
?>
</TABLE>
-
thanks a lot mate that was very helpful
i don't know how to deal with timeout tho it has to timeout first to display me those data for 30 seconds the script is executing i just want it to open connection display data and close then ill put all of those in a table to display flight numbers etc
ill figure it out, have you done personally anything useful with those radarbox data? like put them on your website ? any idea where i can get more resources considering that ? (probably more commands etc)
is the one you showed me the only command i can give to radar box to output me the data or there are more ?
cheers mate
-
You can leave the php timeout alone and exit from your port reading loop before that (by using php time functions). Then after a bit more time you can use the update meta tag to update the whole page and start the process again.
What you really want to be able to do is to redraw your table each time a new message is read by your webpage. Ideally you would like to refresh just your table and keep reading messages but I don't think you can do this with php. ASP.Net can refresh part of an html page though.
Another solution might be to make use of mySql together with php. You could use something like a Perl script separate from html to read the port 30003 data to the mySql database and then get the php to display from that database, though again the php page would need to auto-update. I've used this type of setup with Perl/mySql/php to get aviation METAR/TAF data from the net and display the current weather or a weather forecast on a map.
I am the author of SquawkBox (http://www.gfrost.co.uk/SquawkBox/ (http://www.gfrost.co.uk/SquawkBox/)) which reads the port 30003 data you have been looking at and displays a squawk code description for each flight in a scrolling window.
As far as outputs from RadarBox are concerned, you might want to look at the recorded files. These contain more information than the flight data output to port 30003 as they also contain non-positional flights. Data is also output by RadarBox to port 7879 in XML. It is described on page 83 of the manual.
-
Crikey Andy!
I know that you know what you are talking about, but it's all scribble to me :-)
Seriously though, it's good to see work such as SquawkBox coming out to exploit all the capabilities of RadarBox. I've always wanted to do something with that port 7879 and 30003 data, but it's just beyond me.
I'll keep reading this thread and try to learn a bit more!
-
Agreed. Looks to me like Andy could maybe give us a "master-class" in using port 7879/30003 output. And I'm pretty sure that Andy's Squawkbox addon is the first to have been developed for the Radarbox, and then adopted by the SBS-1 community!!!
-
can i use the same code for the xml port 7879 ?
like
<html>
<body>
<?php
$fp = fsockopen('localhost', 7879, $errno, $errstr);
if (!$fp)
{
echo "$errstr ($errno)<br />\n";
}
else
{
$out = "GET / HTTP/1.1\r\n";
$out .= "Host: localhost\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
while (!feof($fp))
{
echo fgets($fp, 128);
}
fclose($fp);
}
?>
</body>
</html>
cheers
-
Yes you can. You will see something like this...
20081204085814 484006 39000 542 100 0 000 53.2487 -1.2352 000 20081204085815 4004BC MON4177 13375 341 327 -1344 000 52.9074 -1.3171 000 20081204085815 78014F 02780 141 274 640 000 53.3162 -2.3541 000 20081204085817 4CA242 RYR103S 28025 447 301 0 000 52.9134 -1.6948 000 20081204085817 C078AE 08025 316 084 0 000 53.5529 -2.5163 000 20081204085817 4CA56E RYR6123 33750 416 298 -1728 000 53.8648 -3.7095 000 20081204085817 47836D SAS2547 04480 191 231 -1088 000 53.4596 -2.0552 000 20081204085818 3949E9 AFR022 33975 469 323 0 000 52.8271 -1.2371 000 20081204085818 48406B KLM957 22000 454 331 0 000 53.8009 -1.5320 000 20081204085818 4CA250 RYR205 34000 421 297 0 000 53.2564 -1.9241 000 20081204085825 78014F CPA038 02855 152 282 576 000 53.3175 -2.3652 000 20081204085826 484006 39000 542 100 0 000 53.2432 -1.1858 000
Note that the XML is decoded by Internet Explorer so the '<' and '>' are stripped away as compared with the example shown in the pdf manual.
You will have to wait 5 minutes to see this data however as the output on this port is delayed by 5 minutes (it should be on port 30003 as well, and will be in the next version). As a result you will have to change max_execution_time in php.ini to be greater than 5 minutes and during this time the page will do nothing except say "Connecting...".
Note that the recorded files are also delayed by 5 minutes so the filename is created but nothing is written to the file until 5 minutes have elapsed.
-
any idea how i can structure them ? like make them being displayed on tables ? i want to make a flight display like the one on radarbox only display flags flights etc without radar
See http://www.civilaircraftregisters.org/Mode_S_Resources/LogReport/EGLLADSB.asp for an example of a web application powered by the port 30003 output. Although it's driven by an SBS, there is no reason why it shouldn't work equally well with the RadarBox 30003 output.
Hopefully that will give you some ideas.
-
anyone can give me a php example of how to connect to radarbox and relay its data to my website through php ?
cheers
I use the following:
!c:\php -q
<?php
$Locatie="Your Location, Your Country";
$link=mysql_connect('ipadres database','username','password');
if(! $link)
die("Could not connect to MySQL");
$database = "databasename";
mysql_select_db($database)
or die ("could not open $database: ".mysql_error() );
$fp = fsockopen("tcp://127.0.0.1",7879);
while (!feof($fp))
{
$buff1=fgets($fp, 2048);
echo $buff1;
if (strlen($buff1)<>0)
{
$numbers = explode("</MODESMESSAGE>", $buff1,-1);
for($i = 0; $i < count($numbers); $i++)
{
$DateVar = explode("</DATETIME>", $numbers[$i]);
$DateVarModes = strstr($DateVar[0], "<DATETIME>");
$DateVarJaar = substr($DateVarModes,10,4 );
$DateVarMaand = substr($DateVarModes,14,2 );
$DateVarDag = substr($DateVarModes,16,2 );
$DatumString=$DateVarJaar."-".$DateVarMaand."-".$DateVarDag;
if (strlen($DateVarJaar)<>0)
{
$DateVarUur = substr($DateVarModes,18,2 );
$DateVarMin = substr($DateVarModes,20,2 );
$DateVarSec = substr($DateVarModes,22,2 );
$TijdString=$DateVarUur.":".$DateVarMin.":".$DateVarSec ;
if (strlen($DateVarUur)<>0)
{
$CallsVar = explode("</CALLSIGN>", $numbers[$i]);
$CallsVarModes = strstr($CallsVar[0], "<CALLSIGN>");
$CallsVarModes = substr($CallsVarModes,10,50 );
$TweedeElement=$CallsVarModes;
$HexVar = explode("</MODES>", $numbers[$i]);
$HexVarModes = strstr($HexVar[0], "<MODES>");
$HexVarModes = substr($HexVarModes,7,50 );
$DerdeElement=$HexVarModes;
if (strlen($DerdeElement)<>0)
{
if (strlen($TweedeElement)==0)
{
$TweedeElement="---";
}
$query = "INSERT INTO liveid VALUES ('$DerdeElement','$DatumString','$TijdString','$TweedeElement','$Locatie')";
mysql_query($query);
echo $query."\n";
//
// Use this script off line ?
// Remove the // signs for the commands below.
//
//$query = "INSERT INTO liveid VALUES ('$DerdeElement','$DatumString','$TijdString','$TweedeElement','$Locatie');";
//$handle1 = fopen("$DatumString mysqllog.txt", 'a');
//fwrite($handle1, $query);
//fwrite($handle1, "\r\n");
//fclose ($handle1);
}
}
}
}
}
else
{
echo "Buffer Empty"."\n";
//CheckSocket($fp,$Locatie);
}
}
?>
-
right this is what i get:
Buffer Empty 20081209072320 468974 09550 277 270 3200 000 38.0714 23.9220 000 20081209072327 4692CB AEE107 15800 386 176 -960 000 38.2513 23.7194 000 20081209072332 468974 OAL151 10200 278 270 3328 000 38.0714 23.9042 000 20081209072337 4692CB AEE107 15650 377 176 -832 000 38.2352 23.7207 000 20081209072347 4692CB AEE107 15525 372 176 -832 000 38.2179 23.7220 000 20081209072347 468974 OAL151 10750 287 270 1472 000 38.0716 23.8786 000 20081209072357 468974 OAL151 10950 308 270 1024 000 38.0716 23.8601 000 20081209072358 4692CB AEE107 15375 360 176 -832 000 38.1983 23.7235 000 20081209072418 4692CB AEE107 15075 343 176 -576 000 38.1658 23.7260 000 20081209072418 468974 OAL151 11350 338 270 1408 000 38.0719 23.8203 000 20081209072429 468974 OAL151 11550 349 270 1152 000 38.0719 23.8001 000 20081209072429 4692CB AEE107 15000 337 176 -896 000 38.1500 23.7272 000 20081209072439 4692CB AEE107 14750 334 176 -1280 000 38.1328 23.7283 000 20081209072441 468974 OAL151 11750 355 270 896 000 38.0719 23.7751 000 20081209072449 4692CB AEE107 14575 331 176 -1088 000 38.1187 23.7293 000 20081209072455 468974 OAL151 11900 358 270 832 000 38.0721 23.7461 000 20081209072459 4692CB AEE107 14375 323 176 -832 000 38.1026 23.7305 000 20081209072506 468974 OAL151 12025 360 270 0 000 38.0721 23.7208 000 20081209072509 4692CB AEE107 14250 317 176 -768 000 38.0887 23.7315 000 20081209072518 468974 OAL151 12000 361 270 0 000 38.0721 23.6977 000 20081209072519 4692CB AEE107 14125 310 176 -576 000 38.0732 23.7327 000 20081209072528 468974 OAL151 12000 362 269 0 000 38.0721 23.6770 000 20081209072529 4692CB AEE107 14000 307 176 -1344 000 38.0601 23.7338 000 20081209072538 468974 OAL151 12000 362 268 0 000 38.0717 23.6534 000 20081209072540 4692CB AEE107 13550 311 176 -2624 000 38.0446 23.7350 000 20081209072548 468974 OAL151 12000 362 268 0 000 38.0714 23.6325 000 20081209072550 4692CB AEE107 13075 316 176 -2752 000 38.0281 23.7361 000 20081209072600 4692CB AEE107 12600 321 181 -3200 000 38.0146 23.7365 000 20081209072600 468974 OAL151 12000 361 269 0 000 38.0709 23.6082 000 20081209072610 468974 OAL151 12000 360 269 0 000 38.0707 23.5862 000 20081209072610 4692CB AEE107 12050 325 193 -3584 000 37.9997 23.7334 000 20081209072620 468974 OAL151 12000 359 269 0 000 38.0706 23.5656 000 20081209072620 4692CB AEE107 11350 332 200 -3456 000 37.9844 23.7268 000
Fatal error: Maximum execution time of 300 seconds exceeded in C:\wamp\www\index.php on line 23
and the database is empty i created a table and database called "liveid" but nothing gets inserted and data are displayed in a very raw way instead of structured why ?
my modified code
<html>
<head>
<title></title>
</head>
<body>
<?php
$Locatie="Your Location, Your Country";
//mysql shit
$link=mysql_connect('127.0.0.1','root','');
if(! $link) die("Could not connect to MySQL");
$database = "liveid";
mysql_select_db($database)
or die ("could not open $database: ".mysql_error() );
//airnav
$fp = fsockopen("tcp://127.0.0.1",7879);
while (!feof($fp))
{
$buff1=fgets($fp, 2048);
echo $buff1;
if (strlen($buff1)<>0)
{
$numbers = explode("</MODESMESSAGE>", $buff1,-1);
for($i = 0; $i < count($numbers); $i++)
{
$DateVar = explode("</DATETIME>", $numbers[$i]);
$DateVarModes = strstr($DateVar[0], "<DATETIME>");
$DateVarJaar = substr($DateVarModes,10,4 );
$DateVarMaand = substr($DateVarModes,14,2 );
$DateVarDag = substr($DateVarModes,16,2 );
$DatumString=$DateVarJaar."-".$DateVarMaand."-".$DateVarDag;
if (strlen($DateVarJaar)<>0)
{
$DateVarUur = substr($DateVarModes,18,2 );
$DateVarMin = substr($DateVarModes,20,2 );
$DateVarSec = substr($DateVarModes,22,2 );
$TijdString=$DateVarUur.":".$DateVarMin.":".$DateVarSec ;
if (strlen($DateVarUur)<>0)
{
$CallsVar = explode("</CALLSIGN>", $numbers[$i]);
$CallsVarModes = strstr($CallsVar[0], "<CALLSIGN>");
$CallsVarModes = substr($CallsVarModes,10,50 );
$TweedeElement=$CallsVarModes;
$HexVar = explode("</MODES>", $numbers[$i]);
$HexVarModes = strstr($HexVar[0], "<MODES>");
$HexVarModes = substr($HexVarModes,7,50 );
$DerdeElement=$HexVarModes;
if (strlen($DerdeElement)<>0)
{
if (strlen($TweedeElement)==0)
{
$TweedeElement="---";
}
$query = "INSERT INTO `liveid` (1,2,3,4,5) VALUES ('$DerdeElement','$DatumString','$TijdString','$TweedeElement','$Locatie')";
mysql_query($query);
echo $query."\n";
//
// Use this script off line ?
// Remove the // signs for the commands below.
//
//$query = "INSERT INTO liveid VALUES ('$DerdeElement','$DatumString','$TijdString','$TweedeElement','$Locatie');";
//$handle1 = fopen("$DatumString mysqllog.txt", 'a');
//fwrite($handle1, $query);
//fwrite($handle1, "\r\n");
//fclose ($handle1);
}
}
}
}
}
else
{
echo "Buffer Empty"."\n";
//CheckSocket($fp,$Locatie);
}
}
/*
// read data from database and display
mysql_connect("127.0.0.1", "root", "") or die(mysql_error());
mysql_select_db("liveid") or die(mysql_error());
$data = mysql_query("SELECT * FROM liveid")
or die(mysql_error());
Print "<table border cellpadding=3>";
while($info = mysql_fetch_array( $data ))
{
Print "<tr>";
Print "<th>ID:</th> <td>".$info['id'] . "</td> ";
Print "<th>1:</th> <td>".$info['1'] . "</td> ";
Print "<th>2:</th> <td>".$info['2'] . "</td> ";
Print "<th>3:</th> <td>".$info['3'] . "</td> ";
Print "<th>4:</th> <td>".$info['4'] . "</td> ";
Print "<th>5:</th> <td>".$info['5'] . " </td></tr>";
}
Print "</table>";
*/
?>
</body>
</html>
-
20081209072320 468974 09550 277 270 3200 000 38.0714 23.9220 000
-> this seems to be OK.
Fatal error: Maximum execution time of 300 seconds exceeded in C:\wamp\www\index.php on line 23
--> this is a setting in php and can easly be soved by putting set_time_limit(0);; in your php file on the first line.
and the database is empty i created a table and database called "liveid" but nothing gets inserted and data are displayed in a very raw way instead of structured why ?
--> Did you also created a table with the name liveid in your database?
$query = "INSERT INTO `liveid` (1,2,3,4,5) VALUES ('$DerdeElement','$DatumString','$TijdString','$TweedeElement','$Locatie')";
mysql_query($query);
echo $query."\n";
--> this echo should show sometling like : Hexcode, 2008-12-09, 13:02:00, callsign, Your Location, Your Country";
For testing:
place // before the line echo $buff1;
and run the script again.
echo $query."\n"; should be showing something like Hexcode, 2008-12-09, 13:02:00, callsign, Your Location, Your Country";
if not, please let me know
-
ok for the script it shows (i put timer for 60 seconds)
Fatal error: Maximum execution time of 60 seconds exceeded in C:\wamp\www\index.php on line 26
yes both database and table are called liveid is this a problem ?
if data get inserted in database then i can display them as i want for some reason they aren't tho
cheers
-
what i think is going on is no data are inserted to table coz script times out or something, it doesnt complete the cycle no matter how long i put it to timeout either for 2-3 seconds or even 300 it still times out then maybe query doesn't get completed
-
Back to the basics;-)
You are getting data from the port, so that should be working OK.
Could you check the following code?
!c:\php -q
<?php
set_time_limit(0);
$Locatie="Your Location, Your Country";
$link=mysql_connect('ipadres database','username','password');
if(! $link)
die("Could not connect to MySQL");
$database = " databasename";
mysql_select_db($database)
or die ("could not open $database: ".mysql_error() );
$DerdeElement="A9876E";
$DatumString="2008-12-11";
$TijdString="07:54:00";
$TweedeElement="GTI8304";
$query = "INSERT INTO liveid VALUES ('$DerdeElement','$DatumString','$TijdString','$TweedeElement','$Locatie')";
mysql_query($query);
echo $query."\n";
?>
This should insert 1 record into database.
-
probably my wampserver has something wrong nothing happens !!!
ill look it up
-
ok i fixed the problem i installed other wamp version and it does insert 1 record in database. However problem with airnav script still same, script times out after 2 or 3 or 5 seconds (depends for how long i put the timeout for) and nothing gets inserted. I think its because of the time out that nothing gets inserrted but no matter if i put it for 2-310-300 seconds still it will keep "waiting for reply" till that time is reached then say timeout
"Fatal error: Maximum execution time of 2 seconds exceeded in c:\wamp\www\index.php on line 31"
so if database is working ok now its the time out that we should worry about
here is the full code
<html>
<head>
<meta http-equiv="refresh" content="300">
<title></title>
</head>
<body>
<?php
set_time_limit(2);
$Locatie="Greece";
//mysql shit
$link=mysql_connect('127.0.0.1','root','');
if(!$link) die("Could not connect to MySQL");
$database = "airnav";
mysql_select_db($database,$link)
or die ("Could not connect to database");
//airnav
$fp = fsockopen("tcp://127.0.0.1",7879);
while (!feof($fp))
{
$buff1=fgets($fp, 2048);
echo $buff1;
if (strlen($buff1)<>0)
{
$numbers = explode("</MODESMESSAGE>", $buff1,-1);
for($i = 0; $i < count($numbers); $i++)
{
$DateVar = explode("</DATETIME>", $numbers[$i]);
$DateVarModes = strstr($DateVar[0], "<DATETIME>");
$DateVarJaar = substr($DateVarModes,10,4 );
$DateVarMaand = substr($DateVarModes,14,2 );
$DateVarDag = substr($DateVarModes,16,2 );
$DatumString=$DateVarJaar."-".$DateVarMaand."-".$DateVarDag;
if (strlen($DateVarJaar)<>0)
{
$DateVarUur = substr($DateVarModes,18,2 );
$DateVarMin = substr($DateVarModes,20,2 );
$DateVarSec = substr($DateVarModes,22,2 );
$TijdString=$DateVarUur.":".$DateVarMin.":".$DateVarSec ;
if (strlen($DateVarUur)<>0)
{
$CallsVar = explode("</CALLSIGN>", $numbers[$i]);
$CallsVarModes = strstr($CallsVar[0], "<CALLSIGN>");
$CallsVarModes = substr($CallsVarModes,10,50 );
$TweedeElement=$CallsVarModes;
$HexVar = explode("</MODES>", $numbers[$i]);
$HexVarModes = strstr($HexVar[0], "<MODES>");
$HexVarModes = substr($HexVarModes,7,50 );
$DerdeElement=$HexVarModes;
if (strlen($DerdeElement)<>0)
{
if (strlen($TweedeElement)==0)
{
$TweedeElement="---";
}
$query = "INSERT INTO `live` (a,b,c,d,e) VALUES ('$DerdeElement','$DatumString','$TijdString','$TweedeElement','$Locatie')";
mysql_query($query,$link);
echo $query."\n";
//
// Use this script off line ?
// Remove the // signs for the commands below.
//
//$query = "INSERT INTO `live` (a,b,c,d,e) VALUES ('$DerdeElement','$DatumString','$TijdString','$TweedeElement','$Locatie');";
//$handle1 = fopen("$DatumString mysqllog.txt", 'a');
//fwrite($handle1, $query);
//fwrite($handle1, "\r\n");
//fclose ($handle1);
}
}
}
}
}
else
{
echo "Buffer Empty"."\n";
CheckSocket($fp,$Locatie);
}
}
mysql_close($link);
?>
<a href="2.php">check database contents</a>
</body>
</html>
-
Your php script is timing out with an error because you have told it to run for just two seconds before stopping and issuing an error by calling "set_time_limit(2);". You could try doing "set_time_limit(0);" instead as Harry suggested in his example. This should run without a timeout ( see http://uk3.php.net/set_time_limit (http://uk3.php.net/set_time_limit) ).
If you need to exit from the loop that is reading messages from port 7879 to update the rest of the page then you can always monitor the message timestamp supplied in the <DATETIME></DATETIME> couplet or use a php get time function ( see http://www.php.net/manual/en/ref.datetime.php (http://www.php.net/manual/en/ref.datetime.php) ).
-
if i put set time limit to zero then there will be no time limit according to the manual and the default will be applied of php.ini at the max_execution_time
NO MATTER what time i put (even 300 seconds) it will still time out after 300 seconds time duration doesn't matter it seems
as for the time functions im a bit lost i dont know how to do this ~:/
-
According to the php manual, the value supplied with set_time_limit() is "The maximum execution time, in seconds. If set to zero, no time limit is imposed". So zero should mean that the php script runs forever. It won't run forever however because you have set up "<meta http-equiv="refresh" content="300">" which will cause the whole page to reload itself and start again after 300 seconds.
As it is going to take 5 minutes (300 seconds) before any data is transmitted on port 7879 because of the security delay I would have thought that you will need to considerably extend that refresh time in order to receive something on the port before the page refreshes.
You can access the time by using the php function localtime as described in the URL I have posted above, e.g. $time_info = localtime($time,1);
then if you want the minutes you read the variable $time_info['tm_min']
-
ok this
<html>
<head>
<meta http-equiv="refresh" content="500">
<title></title>
</head>
<body>
<?php
$Locatie="Greece";
//mysql shit
$link=mysql_connect('127.0.0.1','root','');
if(!$link) die("Could not connect to MySQL");
$database = "airnav";
mysql_select_db($database,$link)
or die ("Could not connect to database");
//airnav
$fp = fsockopen("tcp://127.0.0.1",7879);
while (!feof($fp))
{
$buff1=fgets($fp, 2048);
echo $buff1;
if (strlen($buff1)<>0)
{
$numbers = explode("</MODESMESSAGE>", $buff1,-1);
for($i = 0; $i < count($numbers); $i++)
{
$DateVar = explode("</DATETIME>", $numbers[$i]);
$DateVarModes = strstr($DateVar[0], "<DATETIME>");
$DateVarJaar = substr($DateVarModes,10,4 );
$DateVarMaand = substr($DateVarModes,14,2 );
$DateVarDag = substr($DateVarModes,16,2 );
$DatumString=$DateVarJaar."-".$DateVarMaand."-".$DateVarDag;
if (strlen($DateVarJaar)<>0)
{
$DateVarUur = substr($DateVarModes,18,2 );
$DateVarMin = substr($DateVarModes,20,2 );
$DateVarSec = substr($DateVarModes,22,2 );
$TijdString=$DateVarUur.":".$DateVarMin.":".$DateVarSec ;
if (strlen($DateVarUur)<>0)
{
$CallsVar = explode("</CALLSIGN>", $numbers[$i]);
$CallsVarModes = strstr($CallsVar[0], "<CALLSIGN>");
$CallsVarModes = substr($CallsVarModes,10,50 );
$TweedeElement=$CallsVarModes;
$HexVar = explode("</MODES>", $numbers[$i]);
$HexVarModes = strstr($HexVar[0], "<MODES>");
$HexVarModes = substr($HexVarModes,7,50 );
$DerdeElement=$HexVarModes;
if (strlen($DerdeElement)<>0)
{
if (strlen($TweedeElement)==0)
{
$TweedeElement="---";
}
$query = "INSERT INTO `live` (a,b,c,d,e) VALUES ('$DerdeElement','$DatumString','$TijdString','$TweedeElement','$Locatie')";
echo $DerdeElement."\n";
echo $DatumString."\n";
echo $TijdString."\n";
echo $TweedeElement."\n";
echo $Locatie."\n";
mysql_query($query,$link);
echo $query."\n";
//
// Use this script off line ?
// Remove the // signs for the commands below.
//
//$query = "INSERT INTO `live` (a,b,c,d,e) VALUES ('$DerdeElement','$DatumString','$TijdString','$TweedeElement','$Locatie');";
//$handle1 = fopen("$DatumString mysqllog.txt", 'a');
//fwrite($handle1, $query);
//fwrite($handle1, "\r\n");
//fclose ($handle1);
}
}
}
}
}
else
{
echo "Buffer Empty"."\n";
// CheckSocket($fp,$Locatie);
}
}
mysql_close($link);
?>
<a href="2.php">check database contents</a>
</body>
</html>
gave me THIS
Buffer Empty Buffer Empty Buffer Empty Buffer Empty Buffer Empty 20081211225914 ABE1B6 DAL153 31975 0 480.0 37.7181 23.8892 480.0 20081211225924 ABE1B6 DAL153 32000 0 479.0 37.7384 23.8700 479.0 20081211225934 ABE1B6 DAL153 32000 0 479.0 37.7573 23.8518 479.0 20081211225944 ABE1B6 DAL153 31975 0 475.0 37.7759 23.8329 475.0 20081211225954 ABE1B6 DAL153 31975 0 474.0 37.7941 23.8144 474.0 20081211230005 ABE1B6 DAL153 31975 0 473.0 37.8113 23.7966 473.0 20081211230015 ABE1B6 DAL153 32000 0 474.0 37.8316 23.7756 474.0 20081211230025 ABE1B6 DAL153 32000 0 476.0 37.8493 23.7570 476.0 20081211230036 ABE1B6 DAL153 31975 0 476.0 37.8680 23.7375 476.0 20081211230046 ABE1B6 DAL153 32000 0 476.0 37.8851 23.7193 476.0 20081211230056 ABE1B6 DAL153 32000 0 474.0 37.9050 23.6982 474.0 20081211230107 ABE1B6 DAL153 32000 0 473.0 37.9227 23.6793 473.0 20081211230117 ABE1B6 DAL153 32000 0 474.0 37.9406 23.6601 474.0 20081211230127 ABE1B6 DAL153 31975 0 477.0 37.9605 23.6390 477.0 20081211230138 ABE1B6 DAL153 31975 0 479.0 37.9808 23.6173 479.0 20081211230148 ABE1B6 DAL153 31975 0 477.0 37.9960 23.5998 477.0 20081211230158 ABE1B6 DAL153 32000 0 473.0 38.0149 23.5770 473.0 20081211230208 ABE1B6 DAL153 32000 0 473.0 38.0300 23.5579 473.0 20081211230218 ABE1B6 DAL153 32000 0 475.0 38.0451 23.5387 475.0 20081211230228 ABE1B6 DAL153 31975 0 480.0 38.0623 23.5157 480.0 20081211230238 ABE1B6 DAL153 31975 0 485.0 38.0760 23.4956 485.0 Buffer Empty Buffer Empty Buffer Empty 20081211230550 4B1696 SWR1842 08775 234 149 -1024 000 37.7086 23.4784 000 20081211230600 4B1696 SWR1842 08700 233 138 -448 000 37.7009 23.4866 000 20081211230610 4B1696 SWR1842 08600 228 136 -640 000 37.6934 23.4955 000 20081211230628 4B1696 SWR1842 08300 223 136 -896 000 37.6792 23.5125 000 20081211230707 484057 39000 464 153 0 000 38.3968 23.7604 000 20081211230730 484057 39000 466 153 0 000 38.3545 23.7877 000 20081211230806 484057 39000 463 153 0 000 38.2855 23.8323 000 20081211230831 484057 39000 466 152 0 000 38.2368 23.8646 000 20081211230847 484057 KLM553 39000 468 153 0 000 38.2061 23.8845 000 20081211230902 484057 KLM553 39000 470 153 0 000 38.1766 23.9032 000 20081211230914 484057 KLM553 39000 476 153 0 000 38.1549 23.9171 000 20081211230927 484057 KLM553 39000 480 153 0 000 38.1273 23.9349 000 20081211230937 484057 KLM553 38975 481 153 0 000 38.1076 23.9476 000 20081211230947 484057 KLM553 38975 482 153 0 000 38.0880 23.9604 000 20081211230957 484057 KLM553 39000 482 152 0 000 38.0680 23.9732 000 20081211231007 484057 KLM553 39000 485 150 0 000 38.0524 23.9840 000 20081211231018 484057 KLM553 39000 489 147 0 000 38.0287 24.0015 000 20081211231030 484057 KLM553 39000 491 144 0 000 38.0049 24.0225 000 20081211231041 484057 KLM553 39000 495 141 0 000 37.9855 24.0401 000 20081211231051 484057 KLM553 39000 497 138 0 000 37.9663 24.0608 000 20081211231138 484057 KLM553 39000 498 136 0 000 37.8877 24.1548 000 Buffer Empty 20081211231249 484057 KLM553 39025 498 136 0 000 37.7696 24.2967 000 Buffer Empty Buffer Empty Buffer Empty Buffer Empty Buffer Empty Buffer Empty Buffer Empty Buffer Empty 20081211232051 468965 22575 346 146 -2112 000 38.539 23.4304 000 Buffer Empty Buffer Empty 20081211232307 468965 OAL208 17350 316 158 -2304 000 38.3558 23.5516 000 20081211232347 468965 OAL208 15525 305 159 -3136 000 38.2990 23.5783 000 20081211232357 468965 OAL208 15000 302 159 -3328 000 38.2865 23.5842 000 20081211232408 468965 OAL208 14350 302 159 -3328 000 38.2719 23.5910 000 20081211232437 468965 OAL208 12875 295 158 -2880 000 38.2354 23.6087 000 20081211232442 468967 23375 361 145 -1728 000 38.5309 23.4441 000 20081211232448 468965 OAL208 12350 292 158 -2944 000 38.2214 23.6156 000 20081211232457 468967 22925 363 145 -1600 000 38.5090 23.4630 000 20081211232458 468965 OAL208 11750 288 157 -3072 000 38.2080 23.6227 000 20081211232507 468967 OAL148 22650 365 145 -1728 000 38.4952 23.4749 000 20081211232509 468965 OAL208 11225 284 157 -3072 000 38.1953 23.6293 000 20081211232520 468965 OAL208 10625 279 158 -3264 000 38.1823 23.6360 000 20081211232530 468965 OAL208 10150 276 159 -2944 000 38.1698 23.6421 000 20081211232540 468965 OAL208 09600 273 159 -3392 000 38.1586 23.6475 000 20081211232550 468965 OAL208 09100 271 159 -3392 000 38.1471 23.6532 000 20081211232600 468965 OAL208 08475 271 162 -3264 000 38.1352 23.6585 000
still nothing in database !!
no timeout this time
-
Ok, now the other way arround:
what gives the following for output?
fp = fsockopen("tcp://127.0.0.1",7879);
while (!feof($fp))
{
$buff1=fgets($fp, 2048);
echo $buff1;
}
The $buff1 should give XML statement. In your example it only seems to give plain text without the xml statements.
Which version of Radarbox are you using?
-
hi just to note i also tried writing the output to a FILE AS WELL (to check) and this also fails !! here is the code
<html>
<head>
<meta http-equiv="refresh" content="500">
<title></title>
</head>
<body>
<?php
$File = "YourFile.txt";
$Handle = fopen($File, 'w');
$arrow="----------------------------------------";
$Locatie="Greece";
//mysql shit
$link=mysql_connect('127.0.0.1','root','');
if(!$link) die("Could not connect to MySQL");
$database = "airnav";
mysql_select_db($database,$link)
or die ("Could not connect to database");
//airnav
$fp = fsockopen("tcp://127.0.0.1",7879);
while (!feof($fp))
{
$buff1=fgets($fp, 2048);
echo $buff1;
if (strlen($buff1)<>0)
{
$numbers = explode("</MODESMESSAGE>", $buff1,-1);
for($i = 0; $i < count($numbers); $i++)
{
$DateVar = explode("</DATETIME>", $numbers[$i]);
$DateVarModes = strstr($DateVar[0], "<DATETIME>");
$DateVarJaar = substr($DateVarModes,10,4 );
$DateVarMaand = substr($DateVarModes,14,2 );
$DateVarDag = substr($DateVarModes,16,2 );
$DatumString=$DateVarJaar."-".$DateVarMaand."-".$DateVarDag;
if (strlen($DateVarJaar)<>0)
{
$DateVarUur = substr($DateVarModes,18,2 );
$DateVarMin = substr($DateVarModes,20,2 );
$DateVarSec = substr($DateVarModes,22,2 );
$TijdString=$DateVarUur.":".$DateVarMin.":".$DateVarSec ;
if (strlen($DateVarUur)<>0)
{
$CallsVar = explode("</CALLSIGN>", $numbers[$i]);
$CallsVarModes = strstr($CallsVar[0], "<CALLSIGN>");
$CallsVarModes = substr($CallsVarModes,10,50 );
$TweedeElement=$CallsVarModes;
$HexVar = explode("</MODES>", $numbers[$i]);
$HexVarModes = strstr($HexVar[0], "<MODES>");
$HexVarModes = substr($HexVarModes,7,50 );
$DerdeElement=$HexVarModes;
if (strlen($DerdeElement)<>0)
{
if (strlen($TweedeElement)==0)
{
$TweedeElement="---";
}
$query = "INSERT INTO `live` (a,b,c,d,e) VALUES ('$DerdeElement','$DatumString','$TijdString','$TweedeElement','$Locatie')";
fwrite($Handle, $arrow);
fwrite($Handle, $DerdeElement);
fwrite($Handle, $DatumString);
fwrite($Handle, $TijdString);
fwrite($Handle, $TweedeElement);
fwrite($Handle, $Locatie);
fwrite($Handle, $Locatie);
fwrite($Handle, $arrow);
print "Data Written";
fclose($Handle);
echo $DerdeElement."\n";
echo $DatumString."\n";
echo $TijdString."\n";
echo $TweedeElement."\n";
echo $Locatie."\n";
mysql_query($query,$link);
echo $query."\n";
//
// Use this script off line ?
// Remove the // signs for the commands below.
//
//$query = "INSERT INTO `live` (a,b,c,d,e) VALUES ('$DerdeElement','$DatumString','$TijdString','$TweedeElement','$Locatie');";
//$handle1 = fopen("$DatumString mysqllog.txt", 'a');
//fwrite($handle1, $query);
//fwrite($handle1, "\r\n");
//fclose ($handle1);
}
}
}
}
}
else
{
echo "Buffer Empty"."\n";
// CheckSocket($fp,$Locatie);
}
}
mysql_close($link);
?>
<a href="2.php">check database contents</a>
</body>
</html>
im using the latest radarbox version in hardware and software i only bought it one week ago
now ill try what you suggested me