Nicknasty Posted March 26, 2021 Share Posted March 26, 2021 Hi Guys, Total PHP Noob here. I’ve run into a brick-wall and would appreciate some words of wisdom. I am working on a fairly complicated (at least to my skill level..) home automation/IOT -project and unexpectedly have a big problem establishing a connection between the Internet and my home network. I’ve spent too many hours trying to solve this and eventually have reverted to a super basic Hello World -example to highlight the issue. I can do this with a browser: http://86.60.161.24 // will echo hello World I can’t do this with my server: <?php $url = 'http://86.60.161.24'; $contents = file_get_contents($url); echo ($contents); ?> It looks like the server-side HTTP -request never “touches” my Arduino-chip. No network activity detected. Obviously there is going to be a lot more data transfer happening but I need to solve this issue first. Is there anything I can do to make this work? Any and all input greatly appreciated. Cheers!! Quote Link to comment https://forums.phpfreaks.com/topic/312384-proper-http-request/ Share on other sites More sharing options...
gw1500se Posted March 26, 2021 Share Posted March 26, 2021 Be more specific. This doesn't work does not help us. What error message are you getting? What is getting echo'ed? Do you have error reporting turned on? error_reporting(E_ALL); P.S. Remove the () in the echo. Quote Link to comment https://forums.phpfreaks.com/topic/312384-proper-http-request/#findComment-1585410 Share on other sites More sharing options...
Nicknasty Posted March 26, 2021 Author Share Posted March 26, 2021 Thanks for helping me out gw1500se, Rather unsurprisingly, my php server fails to open the stream. WARNING:file_get_contents(http://86.60.161.24): failed to open stream: Connection timed out I can access this ip with a browser. Some mysterious force is keeping the pipes shut. Nothing get's echoed and it takes a long time for the script to finish. My php server can access everything else, like cnn.com etc. with the same script. Quote Link to comment https://forums.phpfreaks.com/topic/312384-proper-http-request/#findComment-1585419 Share on other sites More sharing options...
gw1500se Posted March 26, 2021 Share Posted March 26, 2021 You may need to set options that the server expects. I'd use the cURL library to retrieve pages. Quote Link to comment https://forums.phpfreaks.com/topic/312384-proper-http-request/#findComment-1585420 Share on other sites More sharing options...
Barand Posted March 26, 2021 Share Posted March 26, 2021 Have you the correct fopen wrappers enabled? see https://www.php.net/manual/en/function.fopen.php Quote Link to comment https://forums.phpfreaks.com/topic/312384-proper-http-request/#findComment-1585422 Share on other sites More sharing options...
kicken Posted March 26, 2021 Share Posted March 26, 2021 Is your server that is running the code being hosted somewhere outside your network? Maybe you need to setup some port forwarding rules on your router or enable the port in a firewall somewhere. Quote Link to comment https://forums.phpfreaks.com/topic/312384-proper-http-request/#findComment-1585423 Share on other sites More sharing options...
Nicknasty Posted March 26, 2021 Author Share Posted March 26, 2021 2 hours ago, kicken said: Is your server that is running the code being hosted somewhere outside your network? Maybe you need to setup some port forwarding rules on your router or enable the port in a firewall somewhere. I have port forwarding in place and it is working fine. You should get Hello World by accessing the url 86.60.161.24. No such luck with php retrieval Quote Link to comment https://forums.phpfreaks.com/topic/312384-proper-http-request/#findComment-1585427 Share on other sites More sharing options...
Barand Posted March 26, 2021 Share Posted March 26, 2021 Your link times out when I try to access via my browser. Quote Link to comment https://forums.phpfreaks.com/topic/312384-proper-http-request/#findComment-1585428 Share on other sites More sharing options...
kicken Posted March 27, 2021 Share Posted March 27, 2021 3 hours ago, Nicknasty said: You should get Hello World by accessing the url Like Barand, it times out for me also. The remote host does not respond to the the connection attempt. Wireshark shows all the outgoing SYN packets but no replies. Sounds like you have a networking issue. Either your port forwarding/firewall configuration is not setup properly or your ISP may be blocking the port. If you're fairly sure your forward/firewall is correct try different port numbers. Quote Link to comment https://forums.phpfreaks.com/topic/312384-proper-http-request/#findComment-1585435 Share on other sites More sharing options...
Nicknasty Posted March 27, 2021 Author Share Posted March 27, 2021 5 hours ago, kicken said: Like Barand, it times out for me also. The remote host does not respond to the the connection attempt. Wireshark shows all the outgoing SYN packets but no replies. Sounds like you have a networking issue. Either your port forwarding/firewall configuration is not setup properly or your ISP may be blocking the port. If you're fairly sure your forward/firewall is correct try different port numbers. I am seeing a fair amount of traffic so someone from the forum is getting through. I can access this url with my mobile (wifi turned off) but not with my ipad. I am investigating three different problems: - Some clients can reach URL 86.60.161.24, some can't. Why is that? - Is my Arduino board replying to http requests properly or is this the part that throws things off for some clients and my php server - Is there some restriction / do I have correct fopen wrappers enabled at my PHP server as Barand suggested. will continue solving the problem btw, my PHP server is hosted by Bluehost and I am operating it remotely. Quote Link to comment https://forums.phpfreaks.com/topic/312384-proper-http-request/#findComment-1585436 Share on other sites More sharing options...
kicken Posted March 27, 2021 Share Posted March 27, 2021 1 hour ago, Nicknasty said: Some clients can reach URL 86.60.161.24, some can't. Why is that? Unknown. I just tried again and this time it connected successfully. So either your Arduino was simply off when I tried before, or the request is only sometimes blocked. 1 hour ago, Nicknasty said: Is my Arduino board replying to http requests properly or is this the part that throws things off for some clients and my php server The fact that it is working now but wasn't before means it's possible you have a problem in your Arduino code. Are you using a library to handle the TCP/IP stuff and HTTP stuff or is it custom? You'll need to spend some time analyzing your setup trying to determine why there are connection problems. If it's possible to SSH into your external bluehost server that would be helpful as you could SSH in and try connecting with curl and get better feedback. 1 hour ago, Nicknasty said: Is there some restriction / do I have correct fopen wrappers enabled at my PHP server as Barand suggested. I would guess your PHP configuration is fine, but you can use phpinfo() to check the settings. Quote Link to comment https://forums.phpfreaks.com/topic/312384-proper-http-request/#findComment-1585437 Share on other sites More sharing options...
Nicknasty Posted March 27, 2021 Author Share Posted March 27, 2021 Have to say I am fairly disappointed with the Phpfreaks forum. I am getting very little advise (thanks anyway for those who participated) but instead seeing 20-30 very childish hacking attempts trying to breach my Arduino board. Shame on you. I'll be closing down this thread and switch my IP so it is sayonara MF's!! If anyone is still interested of helping me instead of just trying to hack me I have one question: Are you able to machine read the current output of http://86.60.161.24 with PHP? If yes, what methods do you use? Quote Link to comment https://forums.phpfreaks.com/topic/312384-proper-http-request/#findComment-1585448 Share on other sites More sharing options...
Barand Posted March 27, 2021 Share Posted March 27, 2021 You're in luck - it didn't time out on me this time <?php $text = file_get_contents('http://86.60.161.24'); echo "<pre>$text</pre>"; ?> Outout analog input 0 is 556 analog input 1 is 465 analog input 2 is 424 analog input 3 is 228 analog input 4 is 364 analog input 5 is 310 Quote Link to comment https://forums.phpfreaks.com/topic/312384-proper-http-request/#findComment-1585450 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.