views:

148

answers:

3

I was wondering is it possible to create a php proxy to a server that listens onlu locally so that the php gateway is public and it directs everything to the server listening on localhost.

This server would be mercurial's hg serve that listens only on 127.0.0.1 and php will do the authentication.

Do You think it's possible to do? Anybody has an idea how to make a general proxy in php so that not only http get works, but also hg push?

I know there are ways to host mercurial repo with auth, but it's on a plug computer and I don't have a lot of space for more apps etc.

+1  A: 

If you're running your php in apache, then you can probably do what you want with php. Just configure apache to proxy to hgserve (assuming you can't run wsgi or cgi, which is the better solution) and you're set. I don't think there's anything to add in PHP land that apache and hgserve don't already bring to the table.

But, yes, you could reimplemnt Apache's proxy functionality in PHP, though you'll also need to make sure to include support for RangeRequests, which mercurial uses in some situations. Don't forget your RFC2616 caching logic (If- headers, Cache-Control, Expires, Last-Modified, etc.) for efficiency...

Ry4an
+2  A: 

You don’t need to run hg serve.

Instead, use hgweb.cgi or hgwebdir.cgi. These are standard CGI scripts that can be run under Apache. hgweb.cgi serves a single repository, and hgwebdir.cgi serves multiple repositories. They do not require any special modules to be installed on Apache, and you can use all of Apache’s built-in access-control and authentication mechanisms.

The best reference is PublishingRepositories on the Mercurial wiki, which explains how to do this and also compares other options, including ssh, which requires even less setup.

Nate
+2  A: 

If you really want to use PHP, you could use the socket functionalities to do whatever networking you want. (http://ch.php.net/manual/en/ref.sockets.php) And you can use fsockopen to connect to whatever you want. You could combine this and use it in a PHP script which you run by console. Use set_time_limit repeatedly to keep your proxy running. You'll need a lot of knowledge and luck to get this done.

But actually it's really WEIRD what you're doing (see other answers and comments). Whatever reason you have for this configuration, it's wrong.

svens