roguitar Posted July 13, 2020 Share Posted July 13, 2020 Hi, there. I'd like to know if it's possible to use a chat system here (PHP, JS, Websocket). I have a chat system made in php and integrated with a socket by using JS, and in localhost, everytime I want to use it, I have to start the server first using the command below in terminal: php.exe websocket_server.php Is there any way of doing this here? If so, what are the procedures? How do I do this here? Thank you! Quote Link to comment Share on other sites More sharing options...
wolstech Posted July 13, 2020 Share Posted July 13, 2020 If your system opens a port (which it probably does if it needs a server half running), no it won't work on the shared hosting. You could buy a VPS to run it though. If it doesn't need to open a custom port and only has to be accessed by stuff running on the hosting server, it might work using a cron, but leaving things running infinitely like this is a good way to get suspended too because they contribute to load while they're running. Quote Link to comment Share on other sites More sharing options...
roguitar Posted July 13, 2020 Author Share Posted July 13, 2020 If your system opens a port (which it probably does if it needs a server half running), no it won't work on the shared hosting. You could buy a VPS to run it though. If it doesn't need to open a custom port and only has to be accessed by stuff running on the hosting server, it might work using a cron, but leaving things running infinitely like this is a good way to get suspended too because they contribute to load while they're running.Unfortunately, it needs to open a port... Quote Link to comment Share on other sites More sharing options...
Krydos Posted July 14, 2020 Share Posted July 14, 2020 You can do sockets through port 80/443 if you use .htaccess to rewrite. If you'd rather have ssh command line access and the ability to open any ports you want you'll need a vps. https://www.heliohost.org/vps/ Quote Link to comment Share on other sites More sharing options...
roguitar Posted July 14, 2020 Author Share Posted July 14, 2020 You can do sockets through port 80/443 if you use .htaccess to rewrite. If you'd rather have ssh command line access and the ability to open any ports you want you'll need a vps. https://www.heliohost.org/vps/Right! And what exactly do I write inside this .htaccess? Quote Link to comment Share on other sites More sharing options...
roguitar Posted July 14, 2020 Author Share Posted July 14, 2020 You can do sockets through port 80/443 if you use .htaccess to rewrite. If you'd rather have ssh command line access and the ability to open any ports you want you'll need a vps. https://www.heliohost.org/vps/Like this? RewriteEngine On RewriteRule ^websocket_server.php/(.*)$ ws://ricky.heliohost.org:80/?$1 [P,QSA,L] Quote Link to comment Share on other sites More sharing options...
roguitar Posted July 14, 2020 Author Share Posted July 14, 2020 You can do sockets through port 80/443 if you use .htaccess to rewrite. If you'd rather have ssh command line access and the ability to open any ports you want you'll need a vps. https://www.heliohost.org/vps/Or like this? RewriteEngine onRewriteCond %{SERVER_PORT} =80RewriteRule ^(.*) https://olimppius.heliohost.org/chat/server/websocket_server.php [R,L] Quote Link to comment Share on other sites More sharing options...
Krydos Posted July 14, 2020 Share Posted July 14, 2020 Pick a port that isn't already in use, like 4000, and use cgi or cron to start your script running listening on that port. Then use something like this to redirect requests to that portRewriteEngine on RewriteRule ^socket/(.*)$ http://127.0.0.1:4000/$1 [P,QSA,L] Then if you go to olimppius.heliohost.org apache will handle the html/php, but if your requests go to olimppius.heliohost.org/socket/(.*) it will be proxied to the internal port 4000 where your script is listening. Please be aware that port 4000 will not be accessible directly. For example olimppius.heliohost.org:4000 will just time out because the firewall will block it, but the firewall won't block internal ports between apache and your script. Quote Link to comment Share on other sites More sharing options...
roguitar Posted July 15, 2020 Author Share Posted July 15, 2020 (edited) Pick a port that isn't already in use, like 4000, and use cgi or cron to start your script running listening on that port. Then use something like this to redirect requests to that port RewriteEngine on RewriteRule ^socket/(.*)$ http://127.0.0.1:4000/$1 [P,QSA,L] Then if you go to olimppius.heliohost.org apache will handle the html/php, but if your requests go to olimppius.heliohost.org/socket/(.*) it will be proxied to the internal port 4000 where your script is listening. Please be aware that port 4000 will not be accessible directly. For example olimppius.heliohost.org:4000 will just time out because the firewall will block it, but the firewall won't block internal ports between apache and your script. Ok, just have a look at what I've done: in /home/roguitar/public_html/chat/vendor/cboden/ratchet/src/Ratchet/Server/IoServer.phpI set the port as 4000 and the address as 0.0.0.0. in line 67. And in /home/roguitar/public_html/chat/server/websocket_server.php I set the port as 4000 too in line 58. And in /home/roguitar/public_html I created a .htaccess with those lines of code you gave me, but I adapted it more or less like this: RewriteEngine on RewriteRule ^chat/server/(.*)$ http://127.0.0.1:4000/$1 [P,QSA,L]This is because the script of the server is in chat/server/websocket_server.php. But okay... In /home/roguitar/public_html/view.php I set this line (435) here in JS: var websocket_server = new WebSocket("ws://ricky.heliohost.org:4000/"); /* ws://localhost:8080/ AND ports 80/443 */Now, what code do I have to type in this cron or cgi thing there? How do I do this? I'm a total newbie at it. Edited July 15, 2020 by roguitar Quote Link to comment Share on other sites More sharing options...
Krydos Posted July 16, 2020 Share Posted July 16, 2020 Cron is the simpler way to start your socket script, but it can also cause you issues.You're only allowed to do 2 cron executions per day, so if you waste them both debugging then you need to wait until the next day to try again. Running cron 3 or more times could result in your account being suspended.People have a tendency to use cron to start scripts, and then they don't know how to stop the script and the poorly written script runs amok on the server causing massive load and the account ends up suspended for it.If you want to try cron anyways knowing the risks, your command would be something like this/usr/local/bin/ea-php72 /home/roguitar/public_html/chat/server/websocket_server.php First set the cron execution to ONCE A DAY, and then since the server runs on UTC look at this https://www.google.com/search?q=what+time+is+it+utc and set the hour and minute fields to be a few minutes in the future. To stop all of your scripts you can run a cron like thiskillall -u roguitar and set it for a few minutes in the future as well. So one start and one stop and you're done for the day on cron jobs, so make them count. The count resets at midnight UTC so I guess you could run one at 23:58, 23:59, 00:00, and 00:01 and be fine, but if you kept that going you'd be suspended. The better way to do this is to use cgi to start and stop your script. I'm not going to copy/paste everything here from the wiki, but take a look at https://wiki.helionet.org/tutorials/discord-bot#starting-and-stopping-your-bot The same idea can be used to start and stop a php socket script as well. Quote Link to comment Share on other sites More sharing options...
roguitar Posted July 16, 2020 Author Share Posted July 16, 2020 Cron is the simpler way to start your socket script, but it can also cause you issues.You're only allowed to do 2 cron executions per day, so if you waste them both debugging then you need to wait until the next day to try again. Running cron 3 or more times could result in your account being suspended.People have a tendency to use cron to start scripts, and then they don't know how to stop the script and the poorly written script runs amok on the server causing massive load and the account ends up suspended for it.If you want to try cron anyways knowing the risks, your command would be something like this /usr/local/bin/ea-php72 /home/roguitar/public_html/chat/server/websocket_server.php First set the cron execution to ONCE A DAY, and then since the server runs on UTC look at this https://www.google.com/search?q=what+time+is+it+utc and set the hour and minute fields to be a few minutes in the future. To stop all of your scripts you can run a cron like this killall -u roguitar and set it for a few minutes in the future as well. So one start and one stop and you're done for the day on cron jobs, so make them count. The count resets at midnight UTC so I guess you could run one at 23:58, 23:59, 00:00, and 00:01 and be fine, but if you kept that going you'd be suspended. The better way to do this is to use cgi to start and stop your script. I'm not going to copy/paste everything here from the wiki, but take a look at https://wiki.helionet.org/tutorials/discord-bot#starting-and-stopping-your-bot The same idea can be used to start and stop a php socket script as well. Ok, I tried to set the cron job and after that I went to the page https://olimppius.heliohost.org/chat/server/websocket_server.php and this was the message I've got: Service UnavailableThe server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.Additionally, a 503 Service Unavailable error was encountered while trying to use an ErrorDocument to handle the request. What have I done wrong?I set the cron job to run at 13:40 today, according to this time here https://www.google.com/search?q=what+time+is+it+utc because I'm here in Brazil, and at this exact moment, it's 11:02. So, I believe that the server is already initiated, and if I want to stop it, I just create another cron job and set killall -u roguitar , right?.I think this is all due to this problem pointed in the message shown I put above. Quote Link to comment Share on other sites More sharing options...
roguitar Posted July 16, 2020 Author Share Posted July 16, 2020 Cron is the simpler way to start your socket script, but it can also cause you issues.You're only allowed to do 2 cron executions per day, so if you waste them both debugging then you need to wait until the next day to try again. Running cron 3 or more times could result in your account being suspended.People have a tendency to use cron to start scripts, and then they don't know how to stop the script and the poorly written script runs amok on the server causing massive load and the account ends up suspended for it.If you want to try cron anyways knowing the risks, your command would be something like this /usr/local/bin/ea-php72 /home/roguitar/public_html/chat/server/websocket_server.php First set the cron execution to ONCE A DAY, and then since the server runs on UTC look at this https://www.google.com/search?q=what+time+is+it+utc and set the hour and minute fields to be a few minutes in the future. To stop all of your scripts you can run a cron like this killall -u roguitar and set it for a few minutes in the future as well. So one start and one stop and you're done for the day on cron jobs, so make them count. The count resets at midnight UTC so I guess you could run one at 23:58, 23:59, 00:00, and 00:01 and be fine, but if you kept that going you'd be suspended. The better way to do this is to use cgi to start and stop your script. I'm not going to copy/paste everything here from the wiki, but take a look at https://wiki.helionet.org/tutorials/discord-bot#starting-and-stopping-your-bot The same idea can be used to start and stop a php socket script as well. Ok, I tried to set the cron job and after that I went to the page https://olimppius.heliohost.org/chat/server/websocket_server.php and this was the message I've got:Service UnavailableThe server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.Additionally, a 503 Service Unavailable error was encountered while trying to use an ErrorDocument to handle the request. What have I done wrong?I set the cron job to run at 13:40 today, according to this time here https://www.google.com/search?q=what+time+is+it+utc because I'm here in Brazil, and at this exact moment, it's 11:02. So, I believe that the server is already initiated, and if I want to stop it, I just create another cron job and set killall -u roguitar , right?.I think this is all due to this problem pointed in the message shown I put above. I think it's all because of this, lol: Warning: require_once(../vendor/autoload.php): failed to open stream: No such file or directory in /home/roguitar/public_html/chat/server/websocket_server.php on line 9 Fatal error: require_once(): Failed opening required '../vendor/autoload.php' (include_path='.:/opt/cpanel/ea-php72/root/usr/share/pear') in /home/roguitar/public_html/chat/server/websocket_server.php on line 9 Quote Link to comment Share on other sites More sharing options...
Krydos Posted July 16, 2020 Share Posted July 16, 2020 You could try editing /home/roguitar/public_html/chat/server/websocket_server.php on line 9 and change ../vendor/autoload.php to the full path /home/roguitar/...etc The other option is you could edit the cron command to change to the correct directory first. The command would be something like this then: cd /home/roguitar/public_html/chat/server/ && /usr/local/bin/ea-php72 /home/roguitar/public_html/chat/server/websocket_server.php Quote Link to comment Share on other sites More sharing options...
roguitar Posted July 17, 2020 Author Share Posted July 17, 2020 You could try editing /home/roguitar/public_html/chat/server/websocket_server.php on line 9 and change ../vendor/autoload.php to the full path /home/roguitar/...etc The other option is you could edit the cron command to change to the correct directory first. The command would be something like this then: cd /home/roguitar/public_html/chat/server/ && /usr/local/bin/ea-php72 /home/roguitar/public_html/chat/server/websocket_server.php Ok, I did what you suggested, but now I have the following error: Warning: require_once(home/roguitar/public_html/chat/vendor/autoload.php): failed to open stream: No such file or directory in /home/roguitar/public_html/chat/server/websocket_server.php on line 10 Fatal error: require_once(): Failed opening required 'home/roguitar/public_html/chat/vendor/autoload.php' (include_path='.:/opt/cpanel/ea-php72/root/usr/share/pear') in /home/roguitar/public_html/chat/server/websocket_server.php on line 10 Quote Link to comment Share on other sites More sharing options...
Krydos Posted July 18, 2020 Share Posted July 18, 2020 Failed opening required 'home/roguitar/public_html/chat/vendor/autoload.php'See how there is no / at the front? Without that leading / it tries to look for a directory called home in it's present working directory. To be an absolute path it needs the / at the start. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.