Page 1 of 1

fsockopen question

Posted: Wed Feb 07, 2007 5:08 pm
by vwiley1
I am running a dedicated server where a client is using a script called PHProxy.

Basically, PHProxy allows visitors to type in a domain, the web page is retrieved by my server, and then sent back to the visitor. This script uses fsockopen to retrieve the webpage/file.

Imagine this for a moment...

I use the script to download a 10MB file. The server retrieves this file (10MB Incoming Bandwidth) and then the server sends the files to me (10MB Outgoing Bandwidth).

In total, the proxy script consumes 20MB of bandwidth to serve the 10MB file.

Anyhow, apache is not good at tracking the total bandwidth used... only the bytes returned from the header response are counted.

This allows the client to exceed his bandwidth limit because it's not being tracked.

So I thought I would get smart about it.... I put the client on a dedicated IP and was tracking the bandwidth used by that IP. After a day or so, it was obvious that incoming bandwidth was still not being tracked. Outgoing bandwidth is being tracked fine.

What I found, was that even though the client is on a dedicated IP, fsockopen is still connecting from the servers main IP. So all incoming bandwidth (the Proxy Script retrieving the pages/files) can still not be accurately counted. I verified this by visiting one of those "What is my IP Address sites" through his proxy script.

Server runs php 5.2.0 in cgi mode...so everyone can use their own php.ini. Is there a php.ini setting, or something I can add to the fsockopen connection string, that will make it use the clients dedicated IP rather than the servers main IP?

Posted: Wed Feb 07, 2007 6:10 pm
by RobertGonzalez
Is there not enough information in the manual to assist in this? This is a sincere question, as I have not used fsockopen() too much, and certainly not under the constraints that yours must be under.

Posted: Thu Feb 08, 2007 4:40 pm
by vwiley1
The documentation for fsockopen does not cover anything about connecting from a different IP assigned to the server. When I first moved the client to a dedicated IP, I assumed it would happen automatically, but it definently isn't happening.

fsockopen is using the servers default IP, which is the same IP assigned to Apache's Default ServerName (server1.myserver.com).

*NOTE: I am not referring to the ServerName in Apache's VirtualHost Container for my clients domain.

Posted: Thu Feb 08, 2007 5:46 pm
by RobertGonzalez
Ok, just wanted to clarify that.

Posted: Fri Feb 09, 2007 3:25 am
by Mordred
So you're asking if it is possible for you to hack the pentagon or something, and make it appear that it was done from my ip.
Imagine the chaos were that possible ;)
The only possibility is ... if you use a proxy installed on my ip :) :)
-----
From a high-level protocol you can't "spoof" the ip, unless through a proxy (which is exactly what happens in your case).
I don't know how or which software with you calculate the traffic, but logically you can just double the PHProxy traffic and reach the correct ammount.


EDIT:
Oh wait, as I reread it, you've assigned a different IP on the server for connecting with this client?
There are two possibilities, one includes rewriting the PHProxy to use socket_*() functions, and bind the outgoing socket to the desired server IP.
Two, if you can track by hostname instead of ip, make a custom name, like phproxy.myserver.com and make the proxy script accessible only through that name, that way you can isolate the traffic TO the proxy script and double only it.

Posted: Fri Feb 09, 2007 5:23 am
by vwiley1
Oh wait, as I reread it, you've assigned a different IP on the server for connecting with this client?

Exactly, and I have MTRG graphs which show the incoming and outgoing bandwidth for that IP. As mentioned above, outgoing bandwidth (bandwidth from the server to the surfer) is being logged properly to the IP. Incoming bandwidth (from the site the visitor wants to see to the server) is being logged to the servers default shared IP (which is shared by many different clients).

There are two possibilities, one includes rewriting the PHProxy to use socket_*() functions, and bind the outgoing socket to the desired server IP.
Looks like that could work, thanks for pointing me in the right direction.
Two, if you can track by hostname instead of ip, make a custom name, like phproxy.myserver.com and make the proxy script accessible only through that name, that way you can isolate the traffic TO the proxy script and double only it.
Bandwidth is tracked by both hostname and IP, so that is already possible. Unfourtunately, just multiplying by 2 will not give accurate results. There is several reasons... gzipping output to visitor, script timeouts (for large files) where incoming bandwidth is used, but script dies before it can send out.

I will stick with your 1st suggestion, which seems to match exactly what I am trying to do.