Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.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 CURL请求不工作,无法返回任何数据_Php_Curl_Libcurl - Fatal编程技术网

PHP CURL请求不工作,无法返回任何数据

PHP CURL请求不工作,无法返回任何数据,php,curl,libcurl,Php,Curl,Libcurl,可能重复: 我将XML数据发布到一个URL,该URL应该将结果发送给我(echo),而不是将结果发送给我,这是我运行PHP后得到的结果。。我的curl代码在这个结果下面。。。我怀疑下面的CURL代码可能有问题,我如何从发布到URL(mysgproc.php)的XML数据中获得结果,我也发布了URL代码?非常感谢 HTTP/1.1 200 OK Date: Fri, 19 Oct 2012 16:30:26 GMT Server: Apache/2.2.9 (Fedora) Set-Cookie

可能重复:

我将XML数据发布到一个URL,该URL应该将结果发送给我(echo),而不是将结果发送给我,这是我运行PHP后得到的结果。。我的curl代码在这个结果下面。。。我怀疑下面的CURL代码可能有问题,我如何从发布到URL(mysgproc.php)的XML数据中获得结果,我也发布了URL代码?非常感谢

HTTP/1.1 200 OK
Date: Fri, 19 Oct 2012 16:30:26 GMT
Server: Apache/2.2.9 (Fedora)
Set-Cookie: ZDEDebuggerPresent=php,phtml,php3; path=/
Content-Length: 238
Connection: close
Content-Type: text/html

<?xml version="1.0" encoding="UTF-8"?><iniResponseMsg  deliveryTimeStamp="19/10/2012 16:30:26 GMT" messageID="9d085e45-9e9b-11da-befd-0014221b359d" correlationID="69c8277d-77af-4fd9-8cc0-7c30d2963bee"> <state>fail</state></iniResponseMsg>
HTTP/1.1200正常
日期:2012年10月19日星期五格林尼治标准时间16:30:26
服务器:Apache/2.2.9(Fedora)
设置Cookie:ZDEDebuggerPresent=php、phtml、php3;路径=/
内容长度:238
连接:关闭
内容类型:text/html
失败
下面是我的代码

<?php
$url ="http://127.0.0.1/sens/msgproc.php";
$xml_data = file_get_contents("/usr/local/www/data/message_test.xml");
#$header ="POST HTTP/1.0 \r\n";
#$header .="Content-type: text/xml \r\n";
#$header .="Content-length: ".strlen($xml_data)." \r\n";
#$header .="Content-transfer-encoding: text\r\n";
#$header .="Connection: close \r\n\r\n";
#$header .= $xml_data;
$headers = array('Content-Type: text/xml','Content-Transfer-Encoding: text','Connection: close');
$ch = curl_init();
curl_setopt ($ch,CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$xml_data);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
#curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header);
$data = curl_exec($ch);  // if the post is successful , the server will return some data.


#$info = curl_getinfo($ch);
#
#if(!curl_errno($ch))
#   echo 'It took '.$info['total_time'].'seconds to send a request to'.$info['url'];
#
#   else
#

curl_close($ch);
echo $data;
?>

下面是msgproc.php代码

<?php

//$pass='go';

/*******************************************************************************
* COMPONENT NAME:
*  msgproc.php
*
* DESCRIPTION:
*  This script accepts the various XML documents from G*.
*  The document is passed to the correct routine
*  in msgproc.php based on what it is.
*
*******************************************************************************/
require('sensdb.php');
require('dbutil.php');
require('msgproc_util.php');

// first this is to pipe all output to the buffer for loggin later in the file
// echo and print statements will get logged instead of outputted
ob_start();

//$raw_post_data = $HTTP_RAW_POST_DATA;

$raw_post_data = file_get_contents("php://input");

$time_log = date("d/m/Y G:i:s") . ' - aeroastro sensor sys time';

/* CONNECT TO THE DATABASE */
sensdb_connect();

$script_time = date("M-d-Y H:i:s");

// logging variables
$type='';
$byte_count=0;
$message_id='';
$error='';
$error_type='';
$source = $_SERVER['REMOTE_ADDR'];

/*******************************************************************************
* COMPONENT NAME:
*  main process
*
* DESCRIPTION:
*
*******************************************************************************/

/****** formerly function test_read_xml_post() ***********************/
//$fp = fopen("/usr/local/www/data/sensor/sens/message_test.xml", "r");
//$fp = fopen("php://input", "r");

echo "string length:" . strlen($raw_post_data) . ' ';

// reject all data not from Globalstar of development
//if ( $source == "207.88.248.142" ) {
    $data = trim($raw_post_data);
//} else {
//    $data = NULL;
//}

$byte_count += strlen($data);
//fclose($fp);

// test of php5 parsing xml .... much easier
if ( $xml = simplexml_load_string($data) ) {

    // innocent until proven guilty
    $status = true;

    // this will help us find the root element to determine message type
    $dom = dom_import_simplexml($xml);
    $xml_root = $dom->tagName;

    // process stumessages here
    if ( $xml_root == 'stuMessages' ) {

        $type = 'STxMessage';

        // what is the message id
        $xml_messageID = $xml->xpath('/stuMessages/@messageID');
        foreach ( $xml_messageID as $id ) {
            $message_id = $id;
        }

        // what is the packet time
        $packetTimes = $xml->xpath('/stuMessages/@timeStamp');
        foreach ( $packetTimes as $_time ) {
            $packetTime = $_time;
        }

        $time_log .= "\n". $packetTime . ' - globalstar packet time';

        // how many messages
        $message_count = count($xml->xpath('/stuMessages/stuMessage'));

        if ( $message_count >= 1 ) {

            // fomat the sql string
            $sql = get_msglog_sql($type, $source, $byte_count, $message_id, $error );

            if ( mysql_query($sql) ) {

                // get the insert id
                // be careful not to change the sql above which might break  our ability here to get the last insert id
                $incoming_id = mysql_insert_id();

                echo $script_time . " - stu_message packet $message_id logged: insert_id:$incoming_id";
            } else {
                echo $script_time . " - stu_message failed logging";
            }

//            mysql_query("LOCK TABLES STxMessage WRITE");
//            mysql_query("SET AUTOCOMMIT = 0");

            mysql_query("BEGIN");

            foreach( $xml->stuMessage as $stuMessage ) {

                $unixtime    = $stuMessage->unixTime;
                $gps         = $stuMessage->gps;
                $payload    = $stuMessage->payload;
                // convert to an ESN int
                $esn        = $stuMessage->esn;
                $esn        = esn_to_num($esn);

                // test the message time against system time
                // JL 2007
                $time_log .= "\n" . gmdate("d/m/Y H:i:s", "$unixtime") . " - packet stu message time";

                // JL 2006 Apr
                // log message data larger than 255 chars for TSM account a la Tony B
                // these messages don't fit in our DB
                if ( strlen($payload) > 255 ) {

                    // log any output
                    $large_message_log = '/usr/local/www/logs/large_message_log';

                    $sql = 'INSERT INTO STxLargeMessage ( ESN,GPS,Payload,UnixTime,IncomingID) values ("'.$esn.'","'.$gps.'","'.$payload.'","'.$unixtime.'","'.$incoming_id.'")';
                    // Perform Insert of large message
                    $result = @mysql_query($sql);

                    // Let's make sure the file exists and is writable first.
                    if ( is_writable($large_message_log) ) {

                        // The file pointer is at the bottom of the file hence
                        $handle = @fopen($large_message_log, 'a');

                        // Write $response to our opened file.
                        @fwrite($handle, "\n".$data);
                        @fclose($handle);
                    }
                }

                // do we have an ESN for this message
//                $select_esn = 'select ESN from STx where ESN = "'.$esn.'"';
//                $result = mysql_query($select_esn);
//                $result_count = mysql_num_rows($result);

                $sql = 'INSERT INTO STxMessage( ESN,GPS,Payload,UnixTime,IncomingID) values ("'.$esn.'","'.$gps.'","'.$payload.'","'.$unixtime.'","'.$incoming_id.'")';
                // Perform Insert
                $result = mysql_query($sql);

                $GMT_unixtime = gmdate("Y-m-d H:i:s", "$unixtime");

                $update = 'update STx set MessageCount = MessageCount + 1, LastMessageTime = "' . $GMT_unixtime . '" where ESN = "' . $esn . '"';

                // increment the message count by 1
                mysql_query($update);
                unset($update);

                // Check db result
                if ( !$result ) {
                    $status = false;
                    // log the error
                    echo 'Invalid query: ' . mysql_error() . "\n";
                    echo $message .= 'Whole query: ' . $query;
                }
                unset($result);

                unset($unixtime);
                unset($gps);
                unset($payload);
                unset($esn);
            }

            if ( $status ) {
                mysql_query("COMMIT");

            } else {
                mysql_query("ROLLBACK");
            }
//            mysql_query("UNLOCK TABLES");
//            mysql_query("SET AUTOCOMMIT = 1");

        } else { // no data but valid xml, return pass, probably G* "pining" aeroastro for life
            $error = "no data in xml packet id:" . $message_id . "\n";
            echo $error;
        }

        // make our response xml for globalstar
        $response = make_globalstar_response_xml('stuResponseMsg', $message_id, $status);

    } elseif ( $xml_root == 'prvmsgs' ) { // process prvmsgs messages

        /*******************************************************************************
        * COMPONENT NAME:
        *  PRVMSGS
        *
        * DESCRIPTION:
        *  These routines accept the PRVMSGS sent by Globalstar in response to the
        *  INIMSGS that were sent. This routine stores the PRVMSGS into the database,
        *  and also sends a respose message back to Globalstar.
        *
        *******************************************************************************/

        $type = 'PrvMessage';

        // what is the message id
        $xml_messageID = $xml->xpath('/prvmsgs/@prvMessageID');
        foreach ( $xml_messageID as $id ) {
            $message_id = $id;
        }

        // how many messages
        $message_count = count($xml->xpath('/prvmsgs/prvmsg'));

        if ( $message_count >= 1 ) {

            // fomat the sql string for logging
            $sql = get_msglog_sql($type, $source, $byte_count, $message_id, $error );

            if ( mysql_query($sql) ) {
                // get the insert id
                $incoming_id = mysql_insert_id();
                echo $script_time . " - PrvMessage packet $message_id logged";
            } else {
                echo $script_time . " - PrvMessage failed logging";
            }

            mysql_query("BEGIN");

            // loop through the messages
            foreach( $xml->prvmsg as $prvmsg ) {

                $esn = esn_to_num($prvmsg->esn);
                $provid = $prvmsg->provID;
                $tstart = $prvmsg->tStart;
                $tend = $prvmsg->tEnd;
                $txretryminsec = $prvmsg->txRetryMinSec;
                $txretrymaxsec = $prvmsg->txRetryMaxSec;
                $txretries = $prvmsg->txRetries;
                $rfchannel = $prvmsg->rfChannel;

                $sql = 'REPLACE INTO PrvMessage ( ESN, ProvID, TStart, TEnd, TxRetryMinSec, TxRetryMaxSec, TxRetries, RFChannel, IncomingID) values ("'.$esn.'","'.$provid.'","'.$tstart.'","'.$tend.'","'.$txretryminsec.'","'.$txretrymaxsec.'","'.$txretries.'","'.$rfchannel.'","'.$incoming_id.'")';

                // Perform Insert
                $result = mysql_query($sql);

                // insert status "change" record
                $insert_sql = 'insert INTO STxStatusChangeHistory (StatusChangeID, ESN, Status, StatusChangeTimestamp) values ("","'.$esn.'","Provisioned",NOW())';

                // Perform Insert
                $insert = mysql_query($insert_sql);

                // Check result
                if (! $result) {

                    $status = false;
                    // log the error
                    echo 'Invalid provisioning: ' . mysql_error() . "\n";
                    echo 'Whole query: ' . $sql;

                } else {

                    $sql  = 'UPDATE STx SET Status="Provisioned" WHERE ESN ="'.$esn.'"';
                    $result = mysql_query($sql);

                    // Check result
                    if (! $result) {
                        $status = false;
                        // log the error
                        echo 'Invalid STx update during provisioning: ' . mysql_error() . "\n";
                        echo 'Whole query: ' . $sql;
                    }
                }

                unset($result);

                unset($esn);
                unset($provid);
                unset($tstart);
                unset($tend);
                unset($txretryminsec);
                unset($txretrymaxsec);
                unset($txretries);
                unset($rfchannel);

            }

            if ( $status ) {
                mysql_query("COMMIT");
            } else {
                mysql_query("ROLLBACK");
                msglog_update($message_id, "PrvMessage INSERT ERROR");
            }
        }

        // make our response xml for globalstar
        $response = make_globalstar_response_xml('prvResponseMsg', $message_id, $status);

    } elseif ( $xml_root == 'instmsgs' ) { // process instmsgs messages

        /*******************************************************************************
        * COMPONENT NAME:
        *  INSTMSGS
        *
        * DESCRIPTION:
        *  After the VAR gets the PRVMSGS and installs the RTU, it will send the
        *  INSTMSG back here to indicate where the unit was installed.
        *
        *******************************************************************************/

        $type = 'InstMessage';

        // what is the message id
        $xml_messageID = $xml->xpath('/instmsgs/@instMessageID');
        foreach ( $xml_messageID as $id ) {
            $message_id = $id;
        }

        // how many messages
        $message_count = count($xml->xpath('/instmsgs/instmsg'));

        if ( $message_count >= 1 ) {

            // fomat the sql string for logging
            $sql = get_msglog_sql($type, $source, $byte_count, $message_id, $error );

            if ( mysql_query($sql) ) {
                // get the insert id
                $incoming_id = mysql_insert_id();
                echo $script_time . " - InstMessage packet $message_id logged";
            } else {
                echo $script_time . " - InstMessage failed logging";
            }

            mysql_query("BEGIN");

            // loop through the messages
            foreach( $xml->instmsg as $instmsg ) {

                $esn = esn_to_num($instmsg->esn);
                $provid = $instmsg->provID;
                $rfchannel = $instmsg->rfChannel;
                $tactual = $instmsg->tActual;
                $deltat = $instmsg->deltaT;
                $latitude = $instmsg->latitude;
                $longitude = $instmsg->longitude;
                $txretries = $instmsg->txRetries;
                $txoffset = $instmsg->txOffset;
                $txretryminsec = $instmsg->txRetryMinSec;
                $txretrymaxsec = $instmsg->txRetryMaxSec;
                $powerlevel = $instmsg->powerLevel;

                $sql = 'REPLACE INTO InstMessage ( ESN
                ,ProvID
                ,IncomingID
                ,RFChannel
                ,TActual
                ,DeltaT
                ,Latitude
                ,Longitude
                ,TxRetries
                ,TxOffset
                ,TxRetryMinSec
                ,TxRetryMaxSec
                ,PowerLevel ) values ("'.$esn.'"
                ,"'.$provid.'"
                ,"'.$incoming_id.'"
                ,"'.$rfchannel.'"
                ,"'.$tactual.'"
                ,"'.$deltat.'"
                ,"'.$latitude.'"
                ,"'.$longitude.'"
                ,"'.$txretries.'"
                ,"'.$txoffset.'"
                ,"'.$txretryminsec.'"
                ,"'.$txretrymaxsec.'"
                ,"'.$powerlevel.'")';

                // Perform Insert
                $result = mysql_query($sql);

                // Check result
                if (! $result) {

                    $status = false;
                    // log the error
                    echo 'Invalid InstMessage sql: ' . mysql_error() . "\n";
                    echo 'Whole query: ' . $sql;

                } else {

                    $sql  = 'UPDATE STx SET Status="Installed" WHERE ESN ="'.$esn.'"';
                    $result = mysql_query($sql);

                    // Check result
                    if (! $result) {
                        $status = false;
                        // log the error
                        echo 'Invalid STx update during Install: ' . mysql_error() . "\n";
                        echo 'Whole query: ' . $sql;
                    }
                }
                unset($result);
                unset($esn);
                unset($provid);
                unset($tstart);
                unset($tend);
                unset($txretryminsec);
                unset($txretrymaxsec);
                unset($txretries);
                unset($rfchannel);
                unset($txoffset);
                unset($txretryminsec);
                unset($txretrymaxsec);
                unset($powerlevel);
            }

            if ( $status ) {
                mysql_query("COMMIT");
            } else {
                mysql_query("ROLLBACK");
                msglog_update($message_id, "InstMessage INSERT ERROR");
            }
        }

        // make our response xml for globalstar
        $response = make_globalstar_response_xml('instResponseMsg', $message_id, $status);


    } elseif ( $xml_root == 'inimsgs' ) { // process inimsgs messages

        /*******************************************************************************
        * COMPONENT NAME:
        *  INIMSGS
        *
        * DESCRIPTION:
        *  The 'INIMSGS' are the messages sent to begin the provisioning process. The
        *  message contains a range of ESN numbers to be provisiond. The 'INIMSGS'
        *  are forwarded to Globalstar. Then, the 'get_prvmsgs' function is called
        *  to poll the database for the response 'prvmsgs' that Globalstar will send.
        *
        *******************************************************************************/

        $type = 'inimsgs';

        // what is the message id
        $xml_messageID = $xml->xpath('/inimsgs/@iniMessageID');
        foreach ( $xml_messageID as $id ) {
            $message_id = $id;
        }

        // how many messages
        $message_count = count($xml->xpath('/inimsgs/inimsg'));

        if ( $message_count >= 1 ) {

            /* DONT FORGET - have a trigger in the database to set a default route for NASCORP */

            $sql = "INSERT INTO STx (ESN, RouteID, GroupID, SubGroupID, STxModel, STxModelGenType, STxName, Note, Status, FilterProfile) VALUES ";
            $sep = "";

            /* FOR EACH OF THE MESSAGES IN THE PACKET.. .*/
            foreach ( $xml->inimsg as $inimsg ) {

                $groupid = $inimsg->groupID;

                $subgroupid = strlen($inimsg->subGroupID) ?    $inimsg->subGroupID : 'NULL';

                /* FIRST CHECK THAT THE REQUESTED RANGE IS AVAILABLE */
                $esnStart = $inimsg->esnStart;
                $esnEnd   = $inimsg->esnEnd;
                $number   = check_esn_range($esnStart, $esnEnd, $inuse);
                $isreal   = ($inimsg->isReal == 'Yes') ? true : false;
                $route_id = get_route_id($groupid, $inimsg->routeAddress);

                if ( $number > 0 ) {

                    /* SPLIT THE ESN NUMBER INTO MANUFACTURER AND SERIAL NUMBER */
                    $esnS = explode('-', $esnStart);
                    $esnE = explode('-', $esnEnd);

                    /* FOR EACH ESN IN THE SPECIFIED RANGE... */
                    for ( $mfg=(int) $esnS[0]; $mfg <= (int) $esnE[0]; $mfg++ ) {

                        for ( $ser=(int) $esnS[1]; $ser <= (int) $esnE[1]; $ser++ ) {

                            $sxtmodel = $inimsg->stxModel;
                            $sxtmodelgentype='1';

                            switch ($sxtmodel) {
                                case "101-1":
                                    $sxtmodel = '101';
                                    $sxtmodelgentype = "1";
                                break;
                                case "101-2":
                                    $sxtmodel = '101';
                                   $sxtmodelgentype = "2";
                               break;
                                case "101-3":
                                    $sxtmodel = '101';
                                   $sxtmodelgentype = "3";
                               break;
                            }

                            $esn = (($mfg << 23) | $ser);
                            $sql .= $sep;
                            $sql .= sprintf("(%d ,%d ,%d ,%s ,'%s' ,'%s' ,'%s' ,'%s' ,'%s' ,'%s' )",
                             $esn
                            ,$route_id
                            ,$groupid
                            ,$subgroupid
                            ,mysql_escape_string($sxtmodel)
                            ,$sxtmodelgentype
                            ,mysql_escape_string($inimsg->stxName)
                            ,mysql_escape_string($inimsg->note)
                            ,$isreal ? 'Initiated' : 'Fake'
                            ,$inimsg->filterProfile);
                            $sep = ",";
                        }
                    }

                    $groupid     = $inimsg->groupID;
                    $subgroupid = $inimsg->subGroupID;
                    $esnstart     = esn_to_num($inimsg->esnStart);
                    $esnend     = esn_to_num($inimsg->esnEnd);
                    $stxmodel    = $inimsg->stxModel;
                    $stxname     = $inimsg->stxName;
                    // new filter setting
                    $filterprofile     = $inimsg->filterProfile;
                    $routeaddress     = $inimsg->routeAddress;
//                    $mobility         = $inimsg->mobility;
//                    $latdefault     = $inimsg->latDefault;
//                    $londefault     = $inimsg->lonDefault;
                    $stxspacing     = $inimsg->txSpacing;
//                    $txfrequency     = $inimsg->txFrequency;
//                    $trequestedstart = $inimsg->tRequestedStart;
//                    $trequestedend  = $inimsg->tRequestedEnd;
                    $note             = $inimsg->note;
                    $isreal             = $inimsg->isReal;

                    $insert_inimessage = 'INSERT INTO IniMessage (GroupID
                    ,SubGroupID
                    ,ESNStart
                    ,ESNEnd
                    ,STxModel
                    ,STxName
                    ,FilterProfile
                    ,TxSpacing
                    ,RouteAddress
                    ,Note
                    ,IsReal) VALUES ("'.$groupid.'"
                    ,"'.$subgroupid.'"
                    ,"'.$esnstart.'"
                    ,"'.$esnend.'"
                    ,"'.$stxmodel.'"
                    ,"'.$stxname.'"
                    ,"'.$filterprofile.'"
                    ,"'.$stxspacing.'"
                    ,"'.$routeaddress.'"
                    ,"'.$note.'"
                    ,"'.$isreal.'")';

                    mysql_query("BEGIN");

                    if ( mysql_query($insert_inimessage) ) {
                        // not used for anything
                        $inserted = true;
                    } else {
                        $status=false;
                    }

                    unset($groupid);
                    unset($subgroupid);
                    unset($esnstart);
                    unset($esnend);
                    unset($stxmodel);
                    unset($stxname);
                    unset($filterprofile);
                    unset($routeaddress);
                    unset($mobility);
                    unset($stxspacing);
                    unset($note);
                    unset($isreal);

                } else {

                    $status = false;
                    echo $script_time . " invalid ESN range\n".$raw_post_data;
                }
            }

            /* IF THE CONTENTS OF THE MESSAGE LOOKED OK, THEN COMMIT
            IT TO THE DATABASE... */

            /* CREATE THE STx TABLE ENTRIES */
            if ( $status ) {

                if ( $status = mysql_query($sql) ) {
                    mysql_query("COMMIT");
                } else {
                    $doc->errors = mysql_error();
                    mysql_query("ROLLBACK");
                }
            } else {
                $doc->errors = mysql_error();
                mysql_query("ROLLBACK");
            }

        } else {
            $status = false;
            echo $script_time . " no messages in xml \n".$raw_post_data;
        }

        // make our response xml for globalstar
        $response = make_globalstar_response_xml('iniResponseMsg', $message_id, $status);
    }

} else {

    // failed to load xml so lets fail
    $status=false;

    $response = make_globalstar_response_xml('xml_error', 0, $status);    
    echo $script_time . " - xml error\n" . $raw_post_data;
}
// log any output
$msgproc_log = '/usr/local/www/logs/msgproc_log';

// collect any trash here for logging
$buffer_string = ob_get_contents()."\n";

// Let's make sure the file exists and is writable first.
if ( is_writable($msgproc_log) ) {

    // The file pointer is at the bottom of the file hence
    $handle = @fopen($msgproc_log, 'a');

    // Write $response to our opened file.
    @fwrite($handle, $buffer_string);
    @fclose($handle);
}

//empty buffer to logs so that globalstar gets response only
ob_end_clean();

mysql_close();

// send the output for Globalstar to see
echo $response;

?>
标记名;
//在此处处理消息
如果($xml_root=='stuMessages'){
$type='STxMessage';
//消息id是什么
$xml_messageID=$xml->xpath('/stuMessages/@messageID');
foreach($xml\u messageID作为$id){
$message_id=$id;
}
//包的时间是几点
$packetTimes=$xml->xpath('/stuMessages/@timeStamp');
foreach($packetTimes作为$\u时间){
$packetTime=$\u时间;
}
$time_log.=“\n”$packetTime.-globalstar数据包时间”;
//有多少信息
$message_count=count($xml->xpath('/stuMessages/stuMessage');
如果($message\u count>=1){
//fomat sql字符串
$sql=get\u msglog\u sql($type,$source,$byte\u count,$message\u id,$error);
if(mysql_查询($sql)){
//获取插入id
//注意不要更改上面的sql,这可能会破坏我们获取最后一个插入id的能力
$incoming_id=mysql_insert_id();
echo$script\u time。“-stu\u消息包$message\u id logged:insert\u id:$incoming\u id”;
}否则{
echo$script_time。“-stu_消息记录失败”;
}
//mysql_查询(“锁表STxMessage WRITE”);
//mysql_查询(“设置自动提交=0”);
mysql_查询(“开始”);
foreach($xml->stuMessage作为$stuMessage){
$unixtime=$stuMessage->unixtime;
$gps=$stuMessage->gps;
$payload=$stuMessage->payload;
//转换为ESN int
$esn=$stuMessage->esn;
$esn=esn到数量($esn);
//根据系统时间测试消息时间
//JL 2007
$time_log.=“\n”.gmdate(“d/m/Y H:i:s”,“$unixtime”)。“-数据包stu消息时间”;
//JL 2006年4月
//TSM帐户a和B的日志消息数据大于255个字符
//这些消息不适合我们的数据库
如果(strlen($payload)>255){
//记录任何输出
$large_message_log='/usr/local/www/logs/large_message_log';
$sql='插入到STxLargeMessage(ESN、GPS、有效载荷、UnixTime、IncomingID)值(“..ESN.”、“..GPS.”、“..Payload.”、“..UnixTime.”、“..incoming_id.”);
//执行大消息的插入
$result=@mysql\u查询($sql);
//让我们首先确保文件存在并且是可写的。
if(可写($large_message_log)){
//文件指针位于文件的底部,因此
$handle=@fopen($large_message_log,'a');
//将$response写入打开的文件。
@fwrite($handle,“\n”。$data);
@fclose($handle);
}
}
//我们是否有此邮件的ESN
//$select_esn='从STx中选择esn,其中esn=“.$esn.”;
//$result=mysql\u query($select\u esn);
//$result\u count=mysql\u num\u行($result);
$sql='插入到STxMessage(ESN、GPS、有效载荷、UnixTime、IncomingID)值(“..ESN.”、“..GPS.”、“..Payload.”、“..UnixTime.”、“..incoming_id.”);
//执行插入
$result=mysql\u查询($sql);
$GMT_unixtime=gmdate(“Y-m-d H:i:s”,“$unixtime”);
$update='update STx set MessageCount=MessageCount+1,LastMessageTime=“”。$GMT\u unixtime。“”其中ESN=“”。$ESN.”;
//将消息计数增加1
mysql_查询($update);
未结算(更新);
//检查数据库结果
如果(!$result){
$status=false;
//记录错误
回显“无效查询:”.mysql\u错误()。“\n”;
echo$message.=“整个查询:”。$query;
}
未结算($结果);
未设置($unixtime);
unset(全球定位系统);
未结算(有效载荷);
未结算($esn);
}
如果($状态){
mysql_查询(“提交”);
}否则{
mysql_查询(“回滚”);
}
//mysql_查询(“解锁表”);
//mysql_查询(“设置自动提交=1”);
}否则{//没有数据,只有有效的xml,返回pass,可能是G*“pining”aeroastro终身
$error=“xml数据包id中没有数据:“.$message\u id”。\n”;
echo$错误;
}
//为globalstar创建响应xml
$response=make_globalstar_response_xml('stresponsemsg',$message_id,$status);
}elseif($xml_root=='prvmsgs'){//处理prvmsgs消息
/*******************************************************************************
*组件名称:
*PRVMSGS
*
*说明:
echo __LINE__, PHP_EOL; flush(); // every few lines :)
// even followed by a die; to slowly move deeper into the code