Reputation: 47
For my project I have to communicate from my (php) website to remote devices. One of the commands that I need to implement sends a continuous stream of data until it receives more input from the user.
So my question is will this be a problem if I use file_get_contents()
? Or should I use fread()
? My input is in the form of a string which fread()
says I should use file_get_contents()
, however if I use file_get_contents()
will I need to put it in a loop then between packets send data to my device to stop it sending data? Will a loop close my connection and open a new one each time I call file_get_contents()
?
I am also limited on the amount of data I can use per day to the point where if I use file_get_contents()
and it limits on chunk the chunk size of 8KB that is 8% of my data for the day.
Upvotes: 1
Views: 1090
Reputation: 2030
I would use fopen
and use stream_context_create
$options = array(
'http' => array(
'method' => 'GET',
),
);
$context = stream_create_context($options);
$fh = fopen($your_url, 'r', false, $context);
This will allow you to consume the stream as a file. Giving you access to any of the stuff you'd want to do with it... like parse it line by line with fgets
or whatever.
Upvotes: 0
Reputation: 11806
Use fsockopen
, fread
, etc... The purpose of file_get_contents
is file reading, not to send/receive data the way you want.
Upvotes: 3