0

I try to send messages from PHP server to Node.js server. The purpose of the Node.js server is to convey the message forward using the Socket.io and Express.

$NodePage = file_get_contents($NodeServer. "/index.html?&message=". $message);

The server always returns empty string and do not send a message. Same URL in browser working Ok and a message is sent correctly. I also try redirect command.

header("Location: http://xxxxxxx.fi/index.html?message=". $message);

Also returns empty string. Working Ok in web browser. I make PHP calls from C# client.

       HtmlWeb web = new HtmlWeb();
       string tempURL = _url + _htmlMessageStr +
                "?message=" + msg.fullMessage) ;

       HtmlDocument doc = web.Load(tempURL);
       HtmlNodeCollection tags = 
       doc.DocumentNode.SelectNodes(_nodeText);

       _retVal = parse(tags[0].InnerHtml);

Any other data is ok from PHP, except node data (empty string). I tried to retrieve data from other Node.js servers and it restore the data correctly. Something is wrong with my Node.js server but what? Server is hosted by hosting company. The server does not run anything other than Node.js.

  • This will help you more https://stackoverflow.com/questions/3488425/php-ini-file-get-contents-external-url – amku91 Aug 23 '18 at 14:27

2 Answers2

2

This needs to be enabled in the php.ini. The option you are searching for is "allow_url_fopen" and set it to true.

http://php.net/manual/en/filesystem.configuration.php

Markus Zeller
  • 8,516
  • 2
  • 29
  • 35
0

I found the problem. You can not use the file_get_contents command to connect Socket.io to the Node.js server. You need to connect to the socket.io.

This article explains how to do it. enter link description here