关于已保存搜索、程序和安全/性能提示和技巧的电子邮件警报?

发布于 2024-09-19 23:22:51 字数 488 浏览 14 评论 0原文

我为我的用户建立了电子邮件提醒(现在只有 2,000 个) 因此,每天晚上 crontab 都会执行一个 php 脚本,该脚本查询 mysql 以查找与用户保存的搜索匹配的内容。就我而言,这是一个分类网站,但我想了解一下,以防万一我必须为更大的客户构建一些东西,

我担心的是:

  1. 如果我的用户增长 10 倍或 x100 倍?服务器会去吗 碰撞?你有什么建议可以建议吗 管理类似的事情?

  2. 有什么方法可以保护我的文件 cron/nightly_script.php 为 在调用它之外执行的形式 浏览器的网址?考虑 我在 crontab 中使用字符串 像:

    lynx [absolute url/script.php]

  3. 电子邮件爆炸怎么样?对于每个 查询查询是否有结果 脚本发送一封电子邮件,所以这意味着 大量的电子邮件……会是这样吗? 自动视为垃圾邮件并且 那么我可以列入黑名单吗?

谢谢!!!

I built an email alert for my users (now are only 2,000)
so every night a crontab execute a php script that query the mysql to find matches with user's saved search. it's a classified website in my case, but i would like to learn in case i had to build something for bigger clients

my concerns are:

  1. what happen if my user grow x10 or
    x100 times? is the server going to
    crash? there any tip you can suggest
    on manage something like that?

  2. there is any way to protect my file
    cron/nightly_script.php to be
    executed form outside calling it in
    the url of the browser? consider
    tham im using a string in crontab
    like:

    lynx [absolute url/script.php]

  3. what about the email blast? for each
    query if the query has results the
    script sends an email, so it means a
    blast of emails...is it going to be
    considered spam automatically and
    then i could blacklisted?

thanks!!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

梦断已成空 2024-09-26 23:22:56

至于第二个,最好的解决方案是将脚本移到文档根目录之外,这样就无法从浏览器访问它并直接调用它

php [location/script.php]

如果你不能这样做,我会进行IP检查并只允许调用它来自本地主机 IP。

您还可以构建安全检查:存储上次向特定用户发送电子邮件的时间,并在发送另一封电子邮件之前进行检查。这可以防止 crontab 问题以及黑客攻击。

As for number 2, the best solution would be to move the script outside the document root so it's not accessible from a browser and call it directly

php [location/script.php]

If you can't do that, I would do a IP check and only allow it to be called from localhost IP.

You could also build in safe checks: store when the last time you sent a email to a particular user was and check that before sending another. This would protect against crontab problems as well as hackers.

强辩 2024-09-26 23:22:55
  1. 好吧,您可能应该修改您的脚本,以便可以分散负载。例如,您可以让 cron 每天运行 4 次以上,每次执行一定比例的用户群,而不是每天执行一次。

  2. 您可以将其从 Web 服务器目标路径中取出,并将 cron 放在外部无法访问的位置。它可以这样执行: php /location/of/script.php

  3. 我想它会根据您发送给谁而有所不同,但您应该考虑发送此通知的频率。

  1. Well, you should probably modify your script so that you can spread the load. For example, you can have the cron run 4+ times a day and each time it does a percentage of the user base, instead of doing them all once a day.

  2. You can take it out of the web server target path and put the cron somewhere that i not accessible externally. It could be executed like this: php /location/of/script.php

  3. I guess it will vary depending on who you send it to, but you should consider how often you send this notice.

圈圈圆圆圈圈 2024-09-26 23:22:55

第 1 点:监视服务器,观察负载及其运行时间。它不应该使其崩溃,但您可能会发现负载过高并且对网页的请求开始减慢。

但需要注意的一件事是 PHP 的内存垃圾有时可能很奇怪,因此请注意 cron 作业的内存使用情况。如果它达到很高 PHP 将崩溃。

如果问题开始变得严重,那么有很多解决方案;例如,不需要将网络服务器和电子邮件发送在同一台计算机上。只要他们可以访问同一个数据库,就设置第二个服务器仅用于电子邮件发送。这就是云计算的完美用途,租用第二台服务器每晚 4 小时(或其他时间)并在其余时间关闭它。

这只是一个建议......有很多解决方案,这实际上取决于您的情况。

Number 1: Monitor the server, watch the load and the time it takes to run. It shouldn't crash it but you may find you get to the point where the load is to high and requests for web pages start to slow down.

But one thing to watch is PHP's memory garbage can be odd sometimes, so watch memory usage of the cron job. If it gets to high PHP will crash.

If it starts to get to much there are lots of solutions; there is no need to have the web server and the email sending on the same machine for instance. As long as they can access the same DB, set up a 2nd server just for email sending. This is what cloud computing is perfect for, hire a 2nd server 4 hours a night (or whatever) and turn it off the rest of the time.

That's just one suggestion ... there are many solutions and it really depends on your situation.

笨死的猪 2024-09-26 23:22:54

如果我的用户增长 10 倍或
x100 倍?服务器会去吗
碰撞?你有什么建议可以建议吗
管理类似的事情?

由于大量的内存/CPU 使用,您的服务器可能会崩溃/变得非常慢。您应该使用像 redis/beanstalkd/gearmand 这样的消息队列来限制您的电子邮件警报。我更喜欢 redis。使用 阻止 pop/pushpredis 库,支持阻止 pop/push。

有什么方法可以保护我的文件
cron/nightly_script.php 被执行
表单外部在 url 中调用它
浏览器?考虑我使用
crontab 中的字符串如下:

如果要扩展,请不要使用 cron。相反,创建几个守护进程。

  • 1 调度发送消息(这部分也可以是cron)到消息队列,
  • 1 处理发送到消息队列的消息。

守护进程不需要每次都生成,并且生成过程(相对)昂贵。其次,您的脚本不应再调用任何 URL,而应直接调用 PHP 脚本 (CLI)。

电子邮件群发怎么样?对于每个
查询查询是否有结果
脚本发送一封电子邮件,所以这意味着
大量的电子邮件……会是这样吗?
自动认为垃圾邮件,然后
我可以列入黑名单吗?

当使用消息队列时,你可以限制自己!

what happen if my user grow x10 or
x100 times? is the server going to
crash? there any tip you can suggest
on manage something like that?

Your server could crash/get slow as hell because of extensive memory/cpu usage. You should use a message queue like redis/beanstalkd/gearmand to throttle your email alerts. My preference goes out to redis. use the blocking pop/push with predis library which support blocking pop/push.

there is any way to protect my file
cron/nightly_script.php to be executed
form outside calling it in the url of
the browser? consider tham im using a
string in crontab like:

Don't use cron if you want to scale. Instead create couple of daemons.

  • 1 to schedule sending messages(this part could also be cron) to message queue,
  • 1 to process messages send to message queue.

Daemons don't need to be spawned each time and spawning processes is (relative) expensive. Second your script should not call any URL anymore but instead call the PHP scripts directly(CLI).

what about the email blast? for each
query if the query has results the
script sends an email, so it means a
blast of emails...is it going to be
considered spam automatically and then
i could blacklisted?

When using a message queue you can throttle yourself!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文