我有一个硬件,可以在每秒钟内记录数据。我可以使用浏览器连接硬件并使用硬件接口获取实时数据。例如:我可以使用以下命令调用实时数据:
http://192.168.100.120:2345/realtime
这就是我在浏览器中看到的内容:
DM_NumLogChans=5
DM_NumDataModes=1
DM_LogicalChan=1
DM_ChanType=SEQUENTIAL
DM_NumDims=2
DM_DataMode=1
DM_DataModeType=TIMHIS
DM_AxisLabel.Dim1=Time
DM_AxisLabel.Dim2=Value
DM_AxisUnits.Dim1=secs
DM_AxisUnits.Dim2=microstrain
DM_SampleRate=1.000000
DM_TimeBase=0.0
DM_ChanName=bridge_1
DM_UserMin=-583.220764
DM_UserMax=940.916199
DM_Start=
-439.779 -391.875 -680.114 1001.37 0
-442.068 -396.62 -680.945 1001.37 0
-443.571 -399.705 -680.639 1001.37 0
-445.598 -404.848 -684.662 1001.37 0
每秒都会出现一个新行。我想获取这些数据并将其保存到文件中或在我的php程序中实时显示。我怎样才能捕获数据?我试过cURL。我认为这是解决方案,但我对此非常陌生。我很感激你能给我的任何帮助或建议。
答案 0 :(得分:1)
使用您的网址
尝试此代码function curl_download($Url){
// is cURL installed yet?
if (!function_exists('curl_init')){
die('Sorry cURL is not installed!');
}
// OK cool - then let's create a new cURL resource handle
$ch = curl_init();
// Now set some options (most are optional)
// Set URL to download
curl_setopt($ch, CURLOPT_URL, $Url);
// Set a referer
curl_setopt($ch, CURLOPT_REFERER, "http://www.example.org/yay.htm");
// User agent
curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
// Include header in result? (0 = yes, 1 = no)
curl_setopt($ch, CURLOPT_HEADER, 0);
// Should cURL return or print out the data? (true = return, false = print)
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Timeout in seconds
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
// Download the given URL, and return output
$output = curl_exec($ch);
// Close the cURL resource, and free system resources
curl_close($ch);
return $output;
}
echo curl_download("192.168.100.120:2345/realtime");