2

I've made a chat system, which works with AJAX requests. Only after a few minutes to half an hour of chatting, my hosting provider starts blocking people, which is probably because it sees the AJAX requests as an attempted (D)DoS attack.

What are my best options?

RobinJ
  • 5,022
  • 7
  • 32
  • 61

5 Answers5

2

Obviously you've built your ajax chat to load all messages on every ajax-call. Which is way too heavy on the server.

As noted by @Daniil, you'd better use websockets (eg pusher or slanger) to communicate realtime messages.

Luceos
  • 6,629
  • 1
  • 35
  • 65
  • Can you provide an example of how that would have to be done? – RobinJ Aug 31 '12 at 15:09
  • @RobinJ take a look at APE; www.ape-project.org, it should have a demo of a push-messaging chatbox. If you're known with battlefield 3; the web interface also uses pusher for notifying about downtime and maintenance, perhaps for even more stuff. For implementing Slanger I suggest starting with pusher first, use their server (with the free version). Then once it all works switch to slanger (less features, but self-installable). ;) – Luceos Sep 03 '12 at 07:16
  • Here is the example from pusher.com: http://pusher.com/tutorials/realtime_chat_widget – Luceos Sep 03 '12 at 08:24
1
  1. Use websockets when you need to operate with data in realtime.
  2. If you still want to use AJAX, don't make too many requests to your script.
Daniil Ryzhkov
  • 7,416
  • 2
  • 41
  • 58
0

Use a less crappy host?

More seriously, make sure the number of AJAX requests sent is reasonable (one every 5 seconds should be fine). Make sure your host actually allows high activity such as chats, as most shared hosting probably won't.

You might want to get a VDS or even a full dedicated server depending on your needs.

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
0
  1. Move out to a different host.
  2. Optimize the code.

It can't be a firewall issue since you said it works for half an hour before being blocked. That's probably your hosting company's excuse to force you to move to a more expensive package.

Dzhuneyt
  • 8,437
  • 14
  • 64
  • 118
  • I currently pay €12.5/y for a 1.5GB hosting with 20GB bandwidth/mo, unlimited databases, unlimited e-mail addresses, 25 subdomains and unlimited cronjobs. Do you know another hosting company that can give me that (or perhaps a bit less) for the same price? – RobinJ Aug 31 '12 at 15:28
  • 1
    That's way too cheap. I think your host is overselling. – Dzhuneyt Sep 03 '12 at 07:36
  • the fact that you're getting so much for so little is proof enough they will easily shut your site down for any irregularity, like a heavy-load ajax chatbox. – Luceos Sep 03 '12 at 08:13
  • @ColorWP.com ; it's in fact a budgethoster, so you're correct. – Luceos Sep 03 '12 at 08:14
-3

Long polling?

I'm not suggesting that you should not use something like websockets or server sent events but, if for some reason you are unable to, then I guess you could try to reduce the number of AJAX requests by not closing them as soon as you currently do.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Alexei
  • 672
  • 1
  • 5
  • 13
  • The answer length is to ensure the answer has a qualitative value. For example here, wtf is "Long polling", how is that relevant to the question, etc... – Matthieu Napoli Aug 31 '12 at 22:40
  • If you are able to use a computer to join SO and ask questions, then you clearly are able to click on a link. If you are able to write a chat system, then you are able to understand the text that you will find on that page. What else do you want, a novel? Edited: "The answer length is to ensure the answer has a qualitative value" - you mean "quantitative" – Alexei Aug 31 '12 at 22:45
  • This is how SO works: you don't write an answer with only a link. http://meta.stackexchange.com/questions/8231/are-answers-that-just-contain-links-elsewhere-really-good-answers and http://meta.stackoverflow.com/tags/link-only-answers/info – Matthieu Napoli Aug 31 '12 at 22:48
  • A link should be sufficient especially since this is not a wiki and the situation has been discussed on another question. Also thanks for the downvote and I do appreciate your useful comment. That's, umm... it's in the FAQ, I presume. – Alexei Aug 31 '12 at 22:52
  • Did you read the links? `Why are some questions or answers removed?` `barely more than a link to an external site`. A "link" answer is not a good answer, that's SO etiquette. If it has been discussed elsewhere, you need to link to it at least, nobody is psychic and knows it. And you are welcome for the upvote on your other answer (from earlier of course). I am no acting out of revenge or anything. – Matthieu Napoli Aug 31 '12 at 22:57
  • You could simply assume, judging by the fact that I'm on a website for programmers, that I'm a sufficiently intelligent person as to realize the why SO does not accept <30 charaters answers. Otherwise, a "link" answer is a good answer. Hopefully I'm not obliged to copy-paste other people's answers. If you'd simply followed that link, you would be sharing any of your life insights. – Alexei Aug 31 '12 at 23:04
  • I will stop here. I believe my answer was good enough to be considered an answer since it points to a similar topic, but too short because I decided that I didn't want to copy that answer and get a badge or something for some other person's effort. – Alexei Aug 31 '12 at 23:05
  • "Why are some questions or answers removed? barely more than a link to an external site" -> "external site" - I have nothing to add. Congrats for your SO reputation. Have a great night and a pleasant life, cheers! ;) – Alexei Aug 31 '12 at 23:07
  • *you would **not** be sharing any of your life insights (I don't seem to be able to edit that comment) Edit: Yes, I understand why, thank you very much! – Alexei Aug 31 '12 at 23:13