PHP How do I get the broadcast from the bluetooth gateway over the HTTP protocol server?

Now this line prints cont empty: $cont = file_get_contents(’ PHP ://input’);
I wonder if my client configured the connection to the server incorrectly

In addition, is the log added at this interface or at the Linux server

we have a sample data file sample_gateway4_data.txt in the php examples directory. please try to post the content to your WEB API.


curl --data-binary "@./sample_gateway4_data.txt"

Please fix the path for sample_gateway4_data.txt first

How do I use this file?Is it necessary?To introduce in the interface or what?

the content of sample_gateway4_data.txt is what gateway will post to your interface. You can use it to simulate the request of gateway and debug your interface.

  • I should now be gateway data without uploading to the server interface

    If you change the file address to this file, the error will be reported. If you do not use this file, the output cont on line 24 will be null

Now I should be the gateway data has not been uploaded to the server, the server has not received, is it my configuration error?
Could you please give me your contact information? My account of this forum is out of balance right now!

First, the sample_data.txt is just for BLE Gateway V2. Please replace it with sample_gateway4_data.txt instead.
Second, the txt file is just a sample data. You can only use it to test your parsing code. It can’t work for final stage.

BTW. I changed your user level to “regular”. It should make your account to better.

* Still report the error…

* If I change it to this, it will always be empty

change the line to

$data = @msgpack_unpack($cont);

let me know if this work

Here’s a simple parse script


$sampleFile = 'sample_gateway4_data.txt';
$cont = file_get_contents($sampleFile);
$data = @msgpack_unpack($cont);

the output

array(6) {
  string(8) ""
  string(12) ""
  string(12) "807D3ACA33B0"
  array(44) {
    string(39) "2G??D??	 ?4?S??=8v]?a?
"                                     ??L??
  • What is the reason for the lack of real data?

Do you use any framework to build your application? Does it possible disable read php://input?

  • I’m using thinkphp5 and I’ll check it out

If that doesn’t work, check the console for errors and your php settings:

  1. the curl url you used, make sure that url is actually working and not returning errors.
  2. open up another terminal / console window and run tail -f /path/to/the/php/log/file so you can actually see the output of these php calls.
  3. often people get this error: file_get_contents(file://input): failed to open stream: no suitable wrapper could be found which can indicate either a typo of the “file://input” string or the fact that allow_url_fopen is disabled in php (see #5 if unsure)
  4. make sure your code is correct, and by that I mean make sure you’re not typing in incorrect arguments and things… stuff that doesn’t necessarily get underlined in netbeans.
  5. remember, file_get_contents only works when allow_url_fopen is set to true in your PHP settings. thats something that is set in php.ini, but you can also change settings at run time by writing something along the lines of the following code before the other code:
ini_set("allow_url_fopen", true);

File_get_contents is fine, is it because my gateway client is not configured correctly


you should check where the log file of your php settings is placed. run the code to get the information


Is this it?