简体   繁体   English

PHP套接字服务器在本地主机上工作,但在实时服务器上不工作

[英]php socket server works on localhost but not on live server

i am using PHP WebSocket Server 0.2 ( http://code.google.com/p/php-websocket-server/ ) on my development window7 pc using wamp server WAMPServer2.0. 我在使用wamp服务器WAMPServer2.0的开发window7 pc上使用PHP WebSocket Server 0.2( http://code.google.com/p/php-websocket-server/ )。

  1. I did not installed/activated any Apache modules. 我没有安装/激活任何Apache模块。
  2. Just activated php_sockets extension for php. 刚刚为php激活了php_sockets扩展。

My socket server works fine using localhost and LAN IP address on LAN but when i implement same code on with same settings on my live server, it does not works. 我的套接字服务器在LAN上使用本地主机和LAN IP地址可以正常工作,但是当我在实时服务器上以相同的设置实现相同的代码时,它不起作用。

On live server 在实时服务器上

  1. after executing "php socket-server.php" there is no error. 执行“ php socket-server.php”后,没有错误。
  2. But when i try to connect to socket server using javascript, it doesn't connects. 但是,当我尝试使用javascript连接到套接字服务器时,它无法连接。

My live server is CENTOS 5.8, Apache/2.2.20, PHP/5.2.17. 我的实时服务器是CENTOS 5.8,Apache / 2.2.20,PHP / 5.2.17。

What i am doing wrong? 我做错了什么? does Apache needs some extra module? Apache是​​否需要一些额外的模块?

-- EDIT -- -编辑-

Now after contacting support enabled port 9300, but still client cannot connect to server. 现在,在联系支持已启用的端口9300之后,但客户端仍然无法连接到服务器。

But on the server side i have some activity, according to script the client gets disconnect as soon a its connected. 但是在服务器端,我有一些活动,根据脚本,客户端一旦连接就断开连接。

在此处输入图片说明

-- EDIT -- -编辑-

Same script is working fine in http://www.turnkeylinux.org/lampstack on vmware. 在vmware上的http://www.turnkeylinux.org/lampstack中 ,相同的脚本可以正常工作。

Look the answer is simple 看答案很简单

Javascript / Ajax security doesn't support Cross-Domain connections Javascript / Ajax安全性不支持跨域连接

notice that: if your server is located at http://myserver.com and your script is running on http://myserver.com:9300 then javascript will understand that this is a different domain. 注意:如果您的服务器位于http://myserver.com和您的脚本运行http://myserver.com:9300然后JavaScript就明白,这是一个不同的域。

If you want to do so do the following: 如果要这样做,请执行以下操作:

1-Create http-proxy using apache where you'll forward "/live" to http://servers.com:9300 2-Then connect your javascript to /live and the apache proxy will do the job. 1-使用apache创建http-proxy,您将在其中将“ / live”转发到http://servers.com:9300 2-然后将javascript连接到/ live,然后apache代理将完成此工作。

If you're stuck in creating proxy then search for "apache proxy pass for openfire" and you'll find a good example on how to. 如果您不愿意创建代理,请搜索“ openfire的Apache代理密码”,然后会找到一个很好的示例。

Please notice that you'll need root access for this, or you can ask your host admin to add this proxy forwarding for you. 请注意,您将需要root访问权限,或者可以要求主机管理员为您添加此代理转发。

Try to connect from command line to your websocket server with curl or ncat with the highest verbosity level. 尝试使用详细程度最高的curl或ncat从命令行连接到Websocket服务器。 If everything fine, i mean, you receive Upgrade header, than probably the problem is in firewall. 如果一切正常,我的意思是,您会收到Upgrade标头,那么问题可能出在防火墙上。

You can alsoe use a nmap, which help you a lot to determine is there any opened ports within the range you are trying to open websocket connections. 您也可以使用nmap,它可以帮助您确定尝试打开websocket连接的范围内是否有任何打开的端口。

Also on production environment you should have the error reporting level to E_NONE. 同样在生产环境中,您应该将错误报告级别设置为E_NONE。

BTW, which kind of live server do you have (VPS/VDS, dedicated, etc.)? 顺便说一句,您拥有哪种实时服务器(VPS / VDS,专用服务器等)?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 php套接字服务器仅在localhost上有效,而在实时服务器上不可用 - php socket server works only on localhost but not live server php: @fopen 在 localhost 中工作,但在实时服务器中无效 - php: @fopen works in localhost but not in live server phpmailer可在localhost上运行,但不能在实时服务器上运行 - phpmailer works on localhost but not on live server 路由在localhost上有效,但在实时服务器上无效 - Routing works on localhost, but not on live server php 代码在 xampp 本地主机上运行良好,但在实时服务器上运行不正常 - php code works fine on xampp localhost but not working on live server 使用Wordpress的PHP文件下载可在localhost上运行,但不能在实时服务器上运行 - PHP file download with Wordpress works on localhost but not live server PHP Cookies 在本地主机上运行良好,但在实时服务器上不起作用 - PHP Cookies works well on localhost, but it's not working on live server PHP - file_get_contents() 在 localhost 但在实时服务器上完美运行 - PHP - file_get_contents() works perfectly on localhost but on live server AJAX 适用于本地主机,但不适用于实时服务器 - AJAX works on localhost, but doesn't on live server Coinbase OAuth可以在localhost上运行,但不能在实时服务器上运行 - Coinbase OAuth works on localhost but not on live server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM