{"action":"created","issue":{"url":"https://api.github.com/repos/ratchetphp/Ratchet/issues/313","labels_url":"https://api.github.com/repos/ratchetphp/Ratchet/issues/313/labels{/name}","comments_url":"https://api.github.com/repos/ratchetphp/Ratchet/issues/313/comments","events_url":"https://api.github.com/repos/ratchetphp/Ratchet/issues/313/events","html_url":"https://github.com/ratchetphp/Ratchet/issues/313","id":73904217,"number":313,"title":"Some doubts for WebSocket Server...","user":{"login":"fedyfausto","id":3913712,"avatar_url":"https://avatars.githubusercontent.com/u/3913712?v=3","gravatar_id":"","url":"https://api.github.com/users/fedyfausto","html_url":"https://github.com/fedyfausto","followers_url":"https://api.github.com/users/fedyfausto/followers","following_url":"https://api.github.com/users/fedyfausto/following{/other_user}","gists_url":"https://api.github.com/users/fedyfausto/gists{/gist_id}","starred_url":"https://api.github.com/users/fedyfausto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fedyfausto/subscriptions","organizations_url":"https://api.github.com/users/fedyfausto/orgs","repos_url":"https://api.github.com/users/fedyfausto/repos","events_url":"https://api.github.com/users/fedyfausto/events{/privacy}","received_events_url":"https://api.github.com/users/fedyfausto/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/ratchetphp/Ratchet/labels/question","name":"question","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-05-07T08:54:31Z","updated_at":"2015-05-07T22:27:35Z","closed_at":null,"body":"Hello guy's I have some doubts regarding the creation of my WebSocket Server and i wanns ask something to you :)\r\n\r\nI'm creating an Server for Mobile application for write topics and comments (into mysql). Before i ask something i'll show toy my code /logic\r\n\r\n1) This is my start_server.php. This is like \"main\" function and i use this for launch my server.\r\nhttp://pastebin.com/kvcx8NzD\r\n\r\nI realize an XML file for server settings and i load them with loadSettings. Now i think here it's all correct (i hope). Now i wanna try to use the IP Blacklist but i can't recognize how can i use it in this script :( and if you have some suggestion for improve this initial code please tell me.\r\n\r\n2) The start_server create and lunch my server.php:\r\nhttp://pastebin.com/nT3swRa5\r\n\r\nNow in my server i have some objects:\r\n\r\nclients: is original dataobject from test server (i think it will be removed)\r\nrouter: is my special object, with this i route the request from client (i'll show after)\r\nloop: is the main object loop, with this i send PINGs and prevent the connection close\r\nusers: is an array[email] dataset of clients object. with this i can reference the clients into my another classes\r\n\r\n\r\nIn the construnct i add an periodic function where i send PINGs and refresh the setting of server (min version for clients and another)\r\n\r\nin onOpen event function i send an ACK to client (\"Connected\") and recognize (from IP for now) their location\r\n\r\nin onMessage i decode the request from client exec the request (with data if the client send) with router (i'll show you after)\r\n\r\nafter exec the request i send the response (or ack) to the client.\r\n\r\nin onClose i check if the client was logged in or not (in my $users)\r\nif is logged i UNSET the position of my array (and i hope this free the memory)\r\nelse i remove only from clients and close connection (it's right?)\r\n\r\nnow it's correct for now or can i improve my script? (like memory usage or other)\r\n\r\n\r\nNOW i'll show you my idea for manage the request of client, i created the MRC like pattern (Model Router Controller).\r\n\r\nThe logic is:   Client send Request (with controller, function and data if requested) ---> pass all to an Router Object ---> this check if exist that class of controller and that function, if exist create a new object of controller and run that function ----> this function comunicate with model for update data in database -----> return the response to router -----> router return response to client\r\n\r\nNow this is my Router Class:\r\nhttp://pastebin.com/GuQcaFkC\r\n\r\nIn the construct i add ONLY public controllers (i have some controllers only for server)\r\n\r\nBut this object it's really simply, now my doubt is on my Controller - Model logic.. Every time a client request something, the Router create a new Controller and every time a new Controller wad created, it create a private Model. Every time the model need to connect to Database, it create a new DB object for comunicate with DB (i'm using Medoo lib) and after all i REALLY HOPE the server release the memory and close all DB connection in auto. i tried to make an singleton DB object but i think isn't a good idea... so can you tell me (or teach *_*) some improvements ? thx a lot and sorry for my bad english\r\n\r\n\r\nAnother problem is when Linux kill my php process after some days.. so i have edited the NICE value to 19 but when i run hTop and MySQLTuner i see this:\r\n\r\n![test1](https://cloud.githubusercontent.com/assets/3913712/7513159/4d436234-f4b2-11e4-8613-619401f1854d.png)\r\n\r\n![test2](https://cloud.githubusercontent.com/assets/3913712/7513163/54853a72-f4b2-11e4-9451-48dc1bc3ff73.png)\r\n\r\ni see some mysqld process and i don't know if it's right or not"},"comment":{"url":"https://api.github.com/repos/ratchetphp/Ratchet/issues/comments/100037942","html_url":"https://github.com/ratchetphp/Ratchet/issues/313#issuecomment-100037942","issue_url":"https://api.github.com/repos/ratchetphp/Ratchet/issues/313","id":100037942,"user":{"login":"cboden","id":617694,"avatar_url":"https://avatars.githubusercontent.com/u/617694?v=3","gravatar_id":"","url":"https://api.github.com/users/cboden","html_url":"https://github.com/cboden","followers_url":"https://api.github.com/users/cboden/followers","following_url":"https://api.github.com/users/cboden/following{/other_user}","gists_url":"https://api.github.com/users/cboden/gists{/gist_id}","starred_url":"https://api.github.com/users/cboden/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cboden/subscriptions","organizations_url":"https://api.github.com/users/cboden/orgs","repos_url":"https://api.github.com/users/cboden/repos","events_url":"https://api.github.com/users/cboden/events{/privacy}","received_events_url":"https://api.github.com/users/cboden/received_events","type":"User","site_admin":false},"created_at":"2015-05-07T22:27:35Z","updated_at":"2015-05-07T22:27:35Z","body":"I would highly recommend against connecting to the database for each new connection. You should only need one connection for the lifetime of your application to speak to the database.\r\n\r\nAlso, any I/O that is not tied to the React EventLoop will block. "}}