I have a proxy in our office which close all the trafic from certain ports. It's a big office so the Security manager won't open any ports. We need some data through the port 9001 which isn't opened.
To bypass this, I put a php script in my server which outputs an XML which needs to be read in my office network. So, I tested at home with a cUrl and worked flawlessly but it seems that now it's grabing nothing.
Tested with var_dump it shows: boolean false with the curl exec
What other methods could I use?
You could set up a VPN on an allowed port and connect through that. That would probably simplify a lot of other stuff as well. OpenVPN is pretty light and straight-forward to set up.
install a proxy on an external host which is listening on port 80 but fetches from port 9001
Related
I have a reactphp script opening multiple ports for listening. Code comes down to trying to open a socket on port x, if occupied choose port+1.
I've found that I can open multiple sockets for the same port without error message which makes the above method of finding a "free" port invalid:
var_dump($s1 = stream_socket_server("tcp://127.0.0.1:7777", $errno, $errstr));
var_dump($s2 = stream_socket_server("tcp://127.0.0.1:7777", $errno, $errstr));
Both calls return a resource with different id. Why does this happen and is it possible that a port already has an open socket from the same process (without keeping book on the sockets)?
PS.: Opening two sockets from different processes fails as expected.
Related questions: Multiple UDP Sockets to listen for specific source on the same port
Update
See https://3v4l.org/6eWY1, it seems the decribed behaviour applies to Windows versions of PHP only.
Have a look at this technique to test if a port is open.
I get the same results with your code and this technique works for me to identify if a port was already open by the same process.
That could be an option if you don't mind the overhead.
FYI I do not know PHP and I primarily use Linux, so your mileage may vary. It seems though that I might help you with some tcp knowledge. If you already know this, forgive me and ignore my answer ;)
So I don't know how you connected to your server socket and how your server handled the connection, but if it is programmed correctly your server will not occupy the port, hence blocking future connections. You can of course do that if you want to.
Normally when you create a server, you want to have 1 known port, so that multiple clients can connect to it (like port 80 for http). The server uses 'listen' to listen for connections, followed by an 'accept' and finally a 'close'. The accept makes sure that you can get multiple connections via your server port.
Btw:
you can find a free port by opening a socket on port 0.
you can handle multiple sockets via 'select'
a nice book to read up on sockets is Working with Tcp sockets by Jesse Storimer (FYI I don't have stocks, only the book ;). But there are many intros to socket programming if your google fu is with you.
I am new to php and I would like to run a local testing server using easy php at home to work on school projects but when I try to start the easy php server, this error message pops up: Apache port (80) is already used by another application ! Close this application and try to run again the server It then gives me some instructions on how to close the application (by killing processes of selected ports), but when I right on the selected ports, the kill processes option is faded and not clickable. Maybe there something else I need to check or do on my computer to run this local host? Thanks for all help!
Just a shot in the dark but maybe try to close Skype, if you have that running, and then start the server? If I remember correctly Skype listens on port 80 by default. If that's indeed the issue then you can configure Skype not to listen on port 80 in its settings...
That might be related to Skype or the IIS server using port 80. You can configure Skype to use different ports in the preferences. You might try going to "localhost" in your browser and see what comes up as well. If it shows a Microsoft IIS server page then you know that the server is running. Disabling that or turning that off depends upon your operating system. You can probably just look that up on the internet if that is the issue.
I've got a Windows 7 XAMPP setup that I use for quickly testing PHP code. I have been running tests with a PHP WebSocket script I wrote recently, and it works fine on every port I've tested except ports 80 and 443. Neither 80 nor 443 will work with the ws or wss protocol. When I try either port, absolutely nothing will go through and the script will just sit there running forever.
The official WebSocket spec (RFC 6455) states:
The WebSocket Protocol attempts to address the goals of existing
bidirectional HTTP technologies in the context of the existing HTTP
infrastructure; as such, it is designed to work over HTTP ports 80 and
443 ...
And:
By default, the WebSocket Protocol uses port 80 for regular WebSocket
connections and port 443 for WebSocket connections tunneled over
Transport Layer Security (TLS) [RFC2818].
And:
The port component is OPTIONAL; the default for "ws" is port 80, while
the default for "wss" is port 443.
So how am I supposed to get ports 80 and 443 to work?
Thanks.
Edit: Here's the first line of netstat:
I guess that means that I can't use port 80, right?
Typically, this sort of issue would mean one of the following:
Something is already listening on those ports; port bindings cannot be shared by multiple processes.
You may require escalated privileges and don't have permissions to open up a listener on those ports (lower-range ports are usually reserved).
To see if it's the first issue, try using netstat to see what ports you have listeners for:
netstat -a -p TCP -o -n
If it's the second issue, you may have to adjust the way you're running the server so it has the proper permissions.
There may be a workaround (I haven't tried this) to enable port sharing under Windows:
https://msdn.microsoft.com/en-us/library/ms733925(v=vs.110).aspx
...but the behavior may be hard to predict with that sort of setup. Another option is to set up a proxy in IIS (which I assume is what's hogging your port 80).
This answer was last revised on November 20, 2015 at 2 PM EST.
I discovered your question because it is similar to my own during the set up process to install and configure XAMPP on my Windows 10 laptop.
(I will explain in details what happened in my specific situation below, but before that I will put a very quick summarized answer to your question.)
I ran the XAMPP as administrator via right clicking it and choosing that option.
The port problems disappeared seemingly.
Now I can open it normally by left clicking it from the pinned icon on the taskbar without specifying administrator.
The latter result occurred after restarting my computer several times in a 24 hour period.
Wish I knew precisely what changed and how it worked, but it's working perfectly now as far as I can see.
I received some errors in the XAMPP Control Panel on November 17, 2015.
These errors said things similar to the following:
"unable to open process PID 4416"
"port 80 blocked"
"port 443 blocked"
"you are not running as an administrator"
Also, I should mention, that I am working through the steps in Chapter 2, Setting Up a Development Server, in the O'Reilly published text book 4th Edition of Learning PHP, MySQL, & JavaScript With jQuery, CSS, & HTML5 by Robin Nixon.
I also discovered that a command prompt "looking" box had opened which I did not know what to do with, and so I later closed it.
However, to get back on point, specifically it was important to me to set up with server and run it in as similar a way to the text book instructions as possible, so changing default port numbers did not appear to be a good option for me because I was not sure how alter the port number for one thing, such as the main port, might affect other ports, and other things on down the line.
I also was getting a bit confused by some other advice offered about searching, using various methods, to determine what other "things" might be interrupting the ports that my XAMMP was trying to use, akak my Apache server.
It actually appeared as though Apache was the source of the PID 4416, and that nothing was utilizing Port 80 or Port 443 at all. I also checked to see if Port 3306 was being used, because it is mentioned in the text book that it would be the default Port for MySQL, and it was not being used by anything else.
I check these PIDs by going to "Task Manager," then to "Details," then to "PID."
Then, in my Windows 10 laptop, I closed all open windows of any kind, even the XAMMP Control Panel.
Then, I typed XAMMP into the "Search Windows" bar.
When XAMMP appeared, I right clicked on it and chose to run it as Administrator.
When the Control Panel opened in this method, I received no error messages in the Control Panel for XAMMP.
However, when I pinned XAMMP to my task bar and tried to open it in a normal fashion (left-click to open) I received many errors.
But, when I right click on the pinned XAMMP icon on my task bar, and then right click again when the words XAMMP pop up, and then choose "run as administrator" it seems to be error free.
This is a work around type of solution.
I assume it might be helpful to some, but not all.
I hope it helps to shed light on similar issues.
I will be working to solve this completely.
It seems in this particular case I need to find a way to be sure the XAMMP automatically runs as adminisistrator when opened, and must require some adjustments that I simply have not discovered just yet.
I hope this is helpful to others! :)
Most of my knowledge is based in HTML5 and CSS3 and search engine optimization, and so I am working to learn more about server side, and dynamic / interactive scripting at this time.
P.S. Within 24 hours of this initial problem, after several restarts of my laptop, I was able to open XAMPP without error, in a normal fashion, by simply left clicking on the icon that I pinned to my taskbar.
I hope this is helpful as well. :)
Have a great day.
I just curious about how php socket work in term of its structure? I had tried to create a server socket with port 80 which is occupied by my Web server and it run perfectly without error. Is it keeping its own port list instead of using the system port? I hope can get more explanation and clarification.
Thank you for your explanation.
I have a application in nodejs and PHP. For now i am using different both.
Can i run node and apache both on same port 8080
Is, there is any way to run any application both on 8080
Thanks
An port is usually connected only to one application. So you have to use different ports.
Proxy -
But you could for example create an virtual host in apache and configure this host as proxy. In this configuration you could access the node.js server on the same port. The node.js server would run on another port.
For TCP based applications, no. You can have only one application listening on a single port at time. If you had 2 network cards, you could have one application listen on the first IP and the second one on the second IP, both using port 8080.... but I doubt that is your case.
I guess you can run them on UDP protocol, which could allow you to have two applications listen to the same port, but as UDP is unreliable and it doesn't establish connection, just sends/receives packets. You might experience big packet loss on UDP.
So, short answer - no.
Actually, there might be a way using iptables. Add a rule of this nature
iptables -A INPUT \
-p tcp \
-m bpf --bytecode "14,0 0 0 20,177"
-j redirect .. Port 80
Check the first few bytes of the connection, and redirect the connection. Then you can accept both http and node.js on the same port, but have the servers running on separate ports.
The syntax above is incorrect, and I have not tried it, but I know people who have used this strategy successfully.