我最近决定在Zend Framework 2中启动一个项目,并且无法在HostGator共享服务器上运行它.
默认情况下,HostGator的共享服务器在PHP 5.2.2中运行,如果您上传ZF2 Skeleton应用程序,它将无法开箱即用.
此外,如果您碰巧具有对HG共享帐户的SSH访问权限(通常必须请求它),您将无法运行.PHAR文件,因为PHP的CLI版本也是5.2.2.
幸运的是,我得到了它的工作......见下文.
在Firefox(至少)中,如果你按ESC,它将关闭所有打开的WebSockets连接.我需要捕获断开连接并尝试重新连接一旦它再次可用.
这是我试图实现的代码的一个示例,但是我能想出的任何内容都不会捕获错误并允许我优雅地处理它.
看看代码:http://jsfiddle.net/w5aAK/
var url = "ws://echo.websocket.org";
try {
socket = window['MozWebSocket'] ? new MozWebSocket(url) : new WebSocket(url);
socket.onopen = function(){
console.log('Socket is now open.');
};
socket.onerror = function (error) {
console.error('There was an un-identified Web Socket error');
};
socket.onmessage = function (message) {
console.info("Message: %o", message.data);
};
} catch (e) {
console.error('Sorry, the web socket at "%s" is un-available', url);
}
setTimeout(function(){
socket.send("Hello World");
}, 1000);
Run Code Online (Sandbox Code Playgroud)
打开控制台并观察输出.
我在这里做错了,还是因为连接在JS脚本范围之外运行而不可能?
任何输入都会有所帮助.
谢谢!