I am playing around with phpWhois: https://github.com/phpWhois/phpWhois
It's installed, and works great. But I would like to do the WHOIS request via a proxy IP. WHOIS servers often block IP's when they make too many requests, and therefor I want to use various proxies to ensure I don't get blocked.
phpWhois has proxy support as I can set: $allowproxy = true;
But apart from that, I see no documentation on how tell the script which proxies/ports to use. Can anyone point me in the right direction please?
Let's have a look into that source code:
fputs($ptr, trim($query_args) . "\r\n");
I'm sorry, this class doesn't support any proxy. You'll need a SOCKS implementation, and PHP doesn't support that with fputs() on a socket.
However I can recommend my Whois API which reliefs you from that complexity. whois-api-php
would be a PHP client:
$whoisApi = new whoisServerList\WhoisApi("apiKey");
echo $whoisApi->query("whois.verisign-grs.com", "example.net");
Related
I have some PHP code in which XML data is being passed between server and client using sockets. socket_create( AF_INET, SOCK_STREAM, SOL_TCP ), socket_read(), socket_write() are the functions being used to pass XML and not HTTP requests.
Now if I want to use a proxy for client to use to connect through to the server, how can I do that in PHP?
I am new to sockets and from what I have gathered, there exists this library https://github.com/clue/php-socks which I don't fully understand right now but the idea is to setup the middleman using the same library which is essentially the proxy in this case. How would I go about using a SOCKS4/5 proxy obtained from https://www.socks-proxy.net/ or paid ones? Is the above mentioned library the only option? Feels like PHP should have something built in already.
Please advice.
This should be a comment, but it's a bit long.
Feels like PHP should have something built in already
I'm struggling to imagine why it should. PHP is a language designed for serverside web development. Proxies are a client side technology. Having said that the curl extension has comprehensive support for HTTP proxies.
There is no single proxy protocol. Certainly SOCKS and HTTP are the most visible protocols for proxies but there are lots more. Was there a specific reason for choosing SOCKS?
If it were me I would just setup transparent port forwarding using iptables (Linux) or a socat instance or haproxy (Unix, MSWindows).
I'm trying to set up PHP websockets on my website. This works great on my local WAMP server, but on my website I keep getting a warning:
unable to bind address [98]: Address already in use in"
I tried various libraries, but they all return this error.
My guess is that the port I'm using in isn't free. The problem is, that I cannot access terminal since this is a shared server (according to phpinfo() websockets are enabled, btw) so I can't look for free ports. Also tried to use port 0 - but no luck.
Thanks in advance!
EDIT:
For instance, this is some code using https://github.com/Flynsarmy/PHPWebSocket-Chat
// start the server
$Server = new PHPWebSocket();
$Server->bind('message', 'wsOnMessage');
$Server->bind('open', 'wsOnOpen');
$Server->bind('close', 'wsOnClose');
// for other computers to connect, you will probably need to change this to your LAN IP or external IP,
// alternatively use: gethostbyaddr(gethostbyname($_SERVER['SERVER_NAME']))
$Server->wsStartServer($_SERVER['SERVER_ADDR'], 9300);
Well, Bluehost site writes: "We block access to certain ports to help avoid having security holes in the firewall...Purchasing a dedicated IP will allow us to grant you access to the ports you will need to run your specific services on.". The technical support guy told me otherwise. I guess case is closed. Thank you all for your time!
talhof9 I went through similar pain in trying to configure my shared hosting service, I didn't find a direct solution to get a shared *AMP server to support WebSockets, but I found a workaround that will at least let you test the commercial viability of the solution you are putting together (if that is indeed what you are looking for) without paying for all the headache of setting up,configuring and administering your own VPS.
Check out http://www.pusher.com for an easy websocket deployment library, that uses their Node server. The free sandbox version lets you play around to get it working, and once you want to test commercial viability you can upgrade to a paid plan.
Hope this helps!
(note I do not work for Pusher)
Most probably your hosting provider has, somehow, disabled PHP sockets. This makes sense because PHP is used to process webpages not create daemons and you're probably using a regular web hosting plan (not a dedicated server).
I would check in with your hosting provider - support forum or just call them.
I am using Google GeoCoding services.
I have a PHP application which calls the Google Maps API, and receives JSON data.
The function which calls Google Maps host hangs until it times out, but only when I push to Godaddy Virtual Private server.
I have already ssh'd into the server and edited php.ini
I changed "safe mode" to "off"
I get this error message:
Message:
file_get_contents(http://maps.googleapis.com/maps/api/geocode/json?address=xYxY&sensor=false):
failed to open stream: Connection timed out
This works fine in my WAMP server but fails on live server. Any ideas why?
I have found the answer. What has been a week, now? I hope others find this solution. The virtual dedicated servers from GoDaddy are ipv6 enabled, but google maps API is having none of that. So tell Curl to force v4 request, like this:
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
credit is due in part to a blog where I found this information:
http://www.businesscorner.co.uk/disable-ipv6-in-curl-and-php/
Rather than just disabling IPv6, you can try to connect over one IP version and then swap to the other if the first attempt fails. This makes your implementation more robust to temporary routing issues on your and the remote end.
You can get this behavior in file_get_contents() by binding the connection to an interface with either inet6 or inet, and then try the other address family if the first attempt returns FAIL. I wrote up how to make file_get_contents() more routing-robust and dual-stack for anyone that is interested. I also shows you how to force connections to use IPv4 or IPv6 if you prefer to go down that route.
Use curl for getting external data. Many shared servers prevent use of file_get_contents for external data (http://www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen) due to security risks.
Plenty of curl examples online.
Check your network. Google doesn't block such request.
Check here.
I am trying to get into the brave new world of web sockets, but I can't get anything working.
I have downloaded and tried several PHP socket servers, but no joy. They seem very scarce on step-by-step info on what to do to actually get the thing working on your own server.
I am passing the path to the server script as the first argument to new WebSocket() - e.g. 'ws://localhost:33/sockets/server.php'. Is that right?
Should I be passing anything as the second param? I've read up, but I'm not quite sure.
Any help appreciated.
Path that you are passing to WebSockets have nothing to do with actual Path within filesystem.
When WebSocket is connecting to server, it just uses actual address "localhost" in your case, and port "33". Then in HTTP request on handshaking it will take the "path" details which is "/sockets/server.php" in your case, and will put them in handshake, so first line of handshake will look like that:
GET /sockets/server.php HTTP/1.1
So it will be used by you application to decide what to do with it. If you want to use it and make it look like related to actual files or use it your own way.
Here is some info from RFC 6455 on WebSockets URIs.
As well do not use port 33, as it is might be taken by dsp service. Check ports map here.
If you Bind your server side WebSocket to port 33, then it should proceed with connection.
After connection of TCP layer is established, it should proceed through HTTP Requests that is Handshaking.
After that is done, and was success. JavaScript on client side will throw onopen callback. If something went wrong it will throw onerror and onclose events.
After connection is successfully established and WebSocket did proceed through handshaking messaging can be made. Client will receive raw string as message, or binary (if server sends binary data, message with specific opcode). But server will receive data with framing and some header. Browsers do apply deframing automatically so on Client side you dont need to worry about that. But on Server side you have to do it or yourself, or use some existing libraries to handle that for you.
Here is official document of WebSockets protocol: RFC 6455. It has all information you need to know all aspects of WebSockets protocol.
In meantime, you might be interested for looking into ready solutions. And go through their examples.
What I have found till now is that:
proxy (squid) throws error code 417. This is due to HTTP/1.1 header "Expect: 100-continue" which squid does not handles properly
On Suppressing "Expect: 100-continue" header, curl returns incorrect header size
How do I proceed from here ?
I really hate patronizing answers that indicate the person asking the question is an idiot. You see it all the time on this site and it's getting annoying.
for squid try this configuration directive:
ignore_expect_100 on
If the Squid proxy MUST be used AND you cannot fix Squid, then you only have one solution: tunnel the API calls through to a server outside of your network and have that server forward the API calls to Amazon S3 on your behalf.
From a basic view you can just replicate all the S3 calls you use on your external server but you must be aware of the security implications, i.e. restricting the usage of the server to say the external IP address of your Squid server, or even API keys much like Amazon use themselves.
If more flexibility is available try another proxy preferably non-caching like Pound.