Fog Creek Software
Discussion Board




How to call a PHP script on a different server

I need (harumph) to use PHP functionality on a Netware 6 server that does not have PHP installed.

It's a call to a script that converts a page of HTML into printer friendly HTML  using comments to delimit sections meant for printing.

I thought I might be able to get around the no-install-PHP problem by hosting the PHP script on another server that DOES have PHP installed.

Guess what - it doesn't work; variables and the referrer that are passed OK when all of the components are on the same server just don't make it to the server hosting the PHP.

My question is simple (!) - is there any reason that this will never work, or is it worth persevering?

If it should work, is there any specific includes/other magic spells I need to use to get the beast to work?

Mark Sanders
Monday, March 31, 2003

I've done crazy stuff like this in the past and I've had it work.  There is no inherent reason why it should work.

You can redirect any form requests to the PHP server (just change the form action to point to that server) and then have it take over. 

Wayne Venables
Monday, March 31, 2003

Would fsockopen() work?

http://www.php.net/manual/sl/function.fsockopen.php

pb
Monday, March 31, 2003

Would this link be helpful?:

http://www.usenix.org/publications/library/proceedings/ec98/full_papers/reiter/reiter_html/node6.html

Also, you might want to get more in depth as to what process you are using to pass the request to the server with the php?

William C
Monday, March 31, 2003

Create a web form the posts to the php server or supply more information to your problem.


Monday, March 31, 2003

the server sending the request to php is secure https

i think a) i forgot to mention this - d'oh sorry; b) the script isn't handling secure connections - root of my problem

thanks and sorry

Mark Sanders
Monday, March 31, 2003

b) the script isn't handling secure connections - root of my problem

By "the script" I assume you mean the php script. There needs to be SSL setup on the php server.


Monday, March 31, 2003

fsockopen() can do http. https would require cURL.

pb
Monday, March 31, 2003

Maybe i'm a little naive, but isn't a web server (like iis, apache, this netware server this guy mentions, etc.) a socket server?  But, these "socket servers" handle simultaneous users and they contain other nice little goodies?

Anyhoo, is it such a good idea to start opening up your own socket using fsockopen?  Otherwise, why would we need web servers when we could just open up our own socket on a server?

Also, if web servers eventually open and maintain their own sockets "under the covers", what does one gain here by using fsockopen?

I may be off-base, I'm just throwing it out there.  I'm about to do some reading now to research this, because I don't think I've really ever thought this through and really paid attention to what goes on behind the scenes of a web server.

William C
Monday, March 31, 2003

The variables should transfer over to the PHP script just fine.  All you have to do is to make sure that you've either placed all of the variables you want to transfer in the query string of the URL for a GET transfer method, or you can also do a form POST. 

If you have a lot of data to transfer then you'll want to use the POST form method since I recall something about there being a limitation in the length of the query string allowed for GETs. 

I've used the POST form method to allow a Windows based program that sits on the user client's machines to communicate with a PHP script that queries a database with no problems.

HeyMacarana
Monday, March 31, 2003

fsockopen() is just a way to POST/GET to a server from script like LWP::UserAgent in PERL.

pb
Tuesday, April 01, 2003

pb, yes. fsockopen does this by opening its own socket connection on the server.

Doesn't this bypass what the web server does?  The web server is an applicaton on top of the server.  The web server eventually opens up a socket connection to the server and performs a GET/POST.  But before the web server opens this socket connection, it must do some other "web-server' type stuff (whatever that is .. I spent a half-hour googling last night, trying to find some in-depth explanation of what happens under the covers of a web server -- but couldn't find anything).

I could be wrong in my understanding.  Like I said, I've never really looked at this in-depth.  Does anyone here know?  Is bypassing the web server (which is what I think is being done) to open your own socket connection a good idea?

William C
Tuesday, April 01, 2003

fsckopen is used by the TCP/IP client, which in this case is the php script. It does not create a listener so it is not subverting or duplicating the function of the web server.

dmooney
Tuesday, April 01, 2003

D'oh!

Ok...now as I think this through.  To request a web page on a server...the client must open up a socket connection from the client machine and sends a GET/POST ... and the server is listening (web server in this case) for this GET/POST.

So, fsockopen must be doing some of the stuff that a browser would normally do for you? Sockets must get opened on both ends (client/server)?  Hmm...I have to review all this eventually.  I've got some reading to do.  Anyone have any good links?

William C
Tuesday, April 01, 2003

William,

fsocketopen can be used to open up a socket connection to a server that is listening for incoming connections on a particular port.  In the case of web servers, they typically listen for new connections on port 80.  Therefore, fsocketopen could be used as an alternative to a web browser to connect to a web server on port 80 to send http requests and receive responses.

However, the original post in this thread would not need to use fsocketopen since the web server without PHP is actually the one making the request (to convert a page to printable format).  In this case, a web form on the non-PHP enabled server would send a standard HTTP request to the php script sitting on the other web server.  The php script would then return the formatted page.

In addition, sockets may be useful on web servers if some data needs to be exchanged without the overhead of the HTTP layer.  For example, chat rooms, game servers etc.

Hope this helps.

Tom Davies
Wednesday, April 02, 2003

*  Recent Topics

*  Fog Creek Home