Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/244.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 可执行文件有更多数据要发送,但don';I don’我不知道如何向可执行文件发出信号,表示已经发送的数据已被处理并准备好下一个块_Php_Mysql_Function_Url_Get - Fatal编程技术网

Php 可执行文件有更多数据要发送,但don';I don’我不知道如何向可执行文件发出信号,表示已经发送的数据已被处理并准备好下一个块

Php 可执行文件有更多数据要发送,但don';I don’我不知道如何向可执行文件发出信号,表示已经发送的数据已被处理并准备好下一个块,php,mysql,function,url,get,Php,Mysql,Function,Url,Get,全部 这是我在这里的第一个问题,如果我犯了错误,请告诉我。我想尽我所能去学习 话虽如此,我的困境就在这里 我正在尝试修改一些php,以便Microsoft Flight Simulator用作ACARS的程序可以向我的代码发送日志文件,并将数据写入MySQL数据库。我提到的程序将数据分解成1Kb的块,发送第一位,等待代码响应OK beofre再发送下一位,依此类推,直到所有数据都被检索并写入文件(txt)和数据库。这一切都可以很好地进行修改。这是未修改的代码 @define ("MYSQL_CO

全部

这是我在这里的第一个问题,如果我犯了错误,请告诉我。我想尽我所能去学习

话虽如此,我的困境就在这里

我正在尝试修改一些php,以便Microsoft Flight Simulator用作ACARS的程序可以向我的代码发送日志文件,并将数据写入MySQL数据库。我提到的程序将数据分解成1Kb的块,发送第一位,等待代码响应OK beofre再发送下一位,依此类推,直到所有数据都被检索并写入文件(txt)和数据库。这一切都可以很好地进行修改。这是未修改的代码

@define ("MYSQL_CONNECT_INCLUDE", "connect_db.php");        // MySQL     database connection (a sample file is included)
@define ("REPORT_FILE_URL", "http://dcascreenshots.net/fsacars/logs/");             // URL where the complete FSAcars reports will be stored
@define ("REPORT_FILE_PATH", "/home/axeman65/public_html/fsacars/logs/");               // Folder where the complete FSAcars reports will be stored
@define ("ERROR_LOG_PATH", "/home/axeman65/public_html/fsacars/error.log");                 // Folder and filename where the error log is located

/*
 * Error messages */
@define ("ERROR_OPENING_REPORT_FILE","Error opening report file");
@define ("ERROR_WRITING_REPORT_FILE","Error writing report file");
@define ("PILOT_NOT_FOUND","Pilot not found");
@define ("ERROR_IN_PILOT_QUERY","Pilot query error");
@define ("ERROR_INSERTING_PIREP","Error inserting report");



function CheckFSAcarsInfo() {   
    // Verify input
    if (!isset($_GET['pilot'])) { return 0; }

    // Request is not empty
    return 1;
}

function GetFSAcarsInfo() {
/* ************************************************************************************************
   @GetFSAcarsInfo
   Receives inputs sent by FSAcars program and returns an array containing that information

   Inputs: N/A
   Outputs: string array 
   ************************************************************************************************ */

// DO NOT EDIT THIS FUNCTION - THIS FIELDS ARE SENT BY FSACARS
$fsacars_pirep = array (
    "pilot" => $_GET['pilot'],
    "date" => $_GET['date'],
    "time" => $_GET['time'],
    "callsign" => $_GET['callsign'],
    "reg" => $_GET['reg'],
    "origin" => $_GET['origin'],
    "dest" => $_GET['dest'],
    "equipment" => $_GET['equipment'],
    "fuel" => $_GET['fuel'],
    "duration" => $_GET['duration'],
    "distance" => $_GET['distance'],
    "rep_url" => "Dummy",
    "more" => $_GET['more'],
    "fsacars_log" => $_GET['log']   // Get complete FSAcars log
);

/* DEBUG CODE - Write request to log file
*/
$fe = fopen (ERROR_LOG_PATH, "a");
fwrite($fe, "[DEBUG ".date("d.m.y H:i:s")."] PILOT: ".$_GET['pilot']." DATE: ".$_GET['date']." TIME: ".$_GET['time']." CALLSIGN: ".$_GET['callsign']." REG: ".$_GET['reg']." ORIG: ".$_GET['origin']." DEST: ".$_GET['dest']." EQUIP: ".$_GET['equipment']." FUEL: ".$_GET['fuel']." DURATION: ".$_GET['duration']." DIST: ".$_GET['distance']." MORE: ".$_GET['more']." LOG: ".$_GET['log']."\n");
fclose($fe);

return $fsacars_pirep;
}

function SavePIREPFile($pirep_array) {
/* ************************************************************************************************
       @SavePIREPFile
       Receives a string array with FSAcars pireps and creates or appends information to pirep file

   Inputs: string array
   Outputs: 1 sucess, 0 error
   ************************************************************************************************ */

/* Build report filename and URL */
$filename=$pirep_array['pilot'].str_replace("/","",$pirep_array['date']).str_replace(":","",$pirep_array['time']).".txt";
$pirep_array['rep_url']=REPORT_FILE_URL.$pirep_array['pilot']."/".$filename;

/* Parse FsAcars log */
$fsacars_log_lines_array = explode("*",$pirep_array['fsacars_log']);

/* Create or Append FSAcars report file */
$fp = fopen (REPORT_FILE_PATH.$pirep_array['pilot']."/".$filename, "a");

if (!$fp) {
    /* Error opening file */
    $fe = fopen (ERROR_LOG_PATH, "a");
    fwrite($fe, "[ERROR ".date("d.m.y H:i:s")."] PILOT: ".$pirep_array['pilot']." - ".ERROR_OPENING_REPORT_FILE." - ".$filename."\n");
    fclose($fe);

    return 0;
}

/*
* Write all log lines received from FSAcars */
for($i=0;$i<count($fsacars_log_lines_array);$i++) {
        if (!fwrite($fp, $fsacars_log_lines_array[$i] . "\n")) {
            /* Error writing to file */
            $fe = fopen (ERROR_LOG_PATH, "a");
        fwrite($fe, "[ERROR ".date("d.m.y H:i:s")."] PILOT".$pirep_array['pilot']." - ".ERROR_WRITING_REPORT_FILE." - ".$filename."\n");
        fclose($fe);

            return 0;
        }
}    

/* Close file */
fclose($fp);

return 1;
}

function InsertReportIntoDB($pirep_array) {
/* ************************************************************************************************
   @InsertReportIntoDB
   Receives a string array with FSAcars pireps and inserts summary into reports table

   Inputs: string array
   Outputs: 1 sucess, 0 error
   ************************************************************************************************ */

/* If this is the first chunk insert PIREP on database */
if ($pirep_array['more']=="0") {
        /* connect to database */
        include(MYSQL_CONNECT_INCLUDE);

        /*
         * Verify pilot identity (From VA Pilots table) */
        $the_pilot = $pirep_array['pilot'];

        $stmt = "select pilot_id from fsacars_pilots where pilot_num='$the_pilot'";
        $result = mysql_query($stmt);

        /* mysql error */
        if (!$result) {
            $fe = fopen (ERROR_LOG_PATH, "a");
        fwrite($fe, "[ERROR ".date("d.m.y H:i:s")."] ".ERROR_IN_PILOT_QUERY." - Pilot ".$pirep_array['pilot']." - ".mysql_error()." SQL: ".$stmt."\n");
        fclose($fe);

        return 0;
        }

        if (mysql_num_rows($result) == 0) {
            /* Pilot not found */
            $fe = fopen (ERROR_LOG_PATH, "a");
        fwrite($fe, "[ERROR ".date("d.m.y H:i:s")."] ".PILOT_NOT_FOUND." - Pilot ".$pirep_array['pilot']."\n");
        fclose($fe);

        return 0;
        } else {
                /* Pilot found */
                $pilot_id = mysql_result($result,0,"pilot_id");

                /* Insert info on reports table */
                $values = $pilot_id.",'".$pirep_array['date']."','".$pirep_array['time']."','".$pirep_array['callsign']."','".$pirep_array['origin']."','".$pirep_array['dest']."','".$pirep_array['reg']."','".$pirep_array['equipment']."','".$pirep_array['duration']."',".$pirep_array['fuel'].",".$pirep_array['distance'].",'".$pirep_array['rep_url']."'";
                $stmt = "INSERT INTO reports (pilot_id,date,time,callsign,origin_id,destination_id,registration,equipment,duration,fuel,distance,fsacars_rep_url) VALUES ($values)";                    
                $result = mysql_query($stmt);

                if (!$result) {
                    $fe = fopen (ERROR_LOG_PATH, "a");
                    fwrite($fe, "[ERROR ".date("d.m.y H:i:s")."] ".ERROR_INSERTING_PIREP." - Pilot ".$pirep_array['pilot']." - ".mysql_error()." SQL: ".$stmt."\n");
                    fclose($fe);

            return 0;
            }

    /* Close the database connection */
                mysql_close();
        }
    }

    return 1;
}


function main() {
/* ************************************************************************************************
   @main

   Inputs: N/A
   Outputs: "OK" sucess, "NOTOK" error
   ************************************************************************************************ */
$res = CheckFSAcarsInfo();
if ($res == 0) {
    return "NOTOK";
}

$a = GetFSAcarsInfo();

$res = SavePIREPFile($a);
if ($res == 0) {
    return "NOTOK";
}

$res = InsertReportIntoDB($a);
if ($res == 0) {
    return "NOTOK";
}


// Report sucessfully received
return "OK";
}

/* receive_pirep.php return to FSACARS */
$out = main();
echo $out;

?>

我知道这是很多代码,我很抱歉,如果有更好的地方让像我这样的初学者获得帮助,我渴望去那里尝试。我已经仔细研究了一个月,似乎有些事情很简单,但我就是没看到。任何帮助都将不胜感激

我找到了解决办法。事实证明,每次接收到数据包时,整个脚本都会循环执行,第一个函数实际检查是否存在任何内容。否则,脚本将停止。我可以使用

if(strpos($pirep[$i],"TOD Land)!==FALSE) {
include("processdcapirep.php; }

检查日志文件的最后一行。这样,它就不会调用我的查询,直到整个文件都被写入。我很感激收到的每一个回复。这里好像有很多人

我看不出有什么问题?你有错误吗?它不停吗?或者寻求帮助的人应该搜索什么?对不起,我没有提到实际问题!正在讨论的程序是FSAcars,可在以下网址找到。未修改的php代码将接收到的数据分解为1KB的数据块,并将其写入文本文件和数据库。如果我修改代码以包含注释并添加到另一个表中,php会在第一个块后停止,并留下大量字符串为空,从而导致MySQL错误。“在主函数下”?不是“在主功能内部”?提示:尝试手动访问脚本,例如通过web浏览器或通过命令行传递必要的参数。查看是否报告了任何错误。检查PHP错误日志(如果有)。同样在你的代码中,“打开并将数据附加到数据库”部分应该使用mysql\u查询而不是mysql\u结果。不确定我怎么会错过这个,lmz。明天我会试试看,因为今晚很晚,明天是工作日。我会发布结果……有没有办法截取FSAcars创建的URL中发送的数据,以便我可以通过浏览器进行检查?否则的话,我得花相当长的时间来检查变化。
$res = insertdcapirep($a);
if(res==0) {
    return "NOTOK";
}
if(strpos($pirep[$i],"TOD Land)!==FALSE) {
include("processdcapirep.php; }