Table of Contents
回复内容:
Home Backend Development PHP Tutorial 关于给用户发送邮件的一些问题

关于给用户发送邮件的一些问题

Jun 06, 2016 pm 08:38 PM
memcached mysql nginx php redis

现在要给全部用户或者指定用户发送邮件,“发送”操作是由我们后台人员触发的。

发送操作提交后,我们就要给用户发送了,在发送过程中可能会存在一个问题,就是发送了一段时间后,程序因某些原因死掉了,这样就导致一些用户没有收到邮件,所以我的想法是发送前先把数据库里的用户全写入到一个文件中,发送时从文件中取用户,然后再弄个用户发送日志以记录哪些用户发送了,这样出问题后,可以从出问题的“那个地方”接着执行发送.....

不知道我的想法行不行,另外我担心“把数据库中的用户写入到文件中”这个过程所花费的时间会很长,从而导致性能上会存在隐患。谢谢大家讨论我的想法,给些意见或指点!

回复内容:

现在要给全部用户或者指定用户发送邮件,“发送”操作是由我们后台人员触发的。

发送操作提交后,我们就要给用户发送了,在发送过程中可能会存在一个问题,就是发送了一段时间后,程序因某些原因死掉了,这样就导致一些用户没有收到邮件,所以我的想法是发送前先把数据库里的用户全写入到一个文件中,发送时从文件中取用户,然后再弄个用户发送日志以记录哪些用户发送了,这样出问题后,可以从出问题的“那个地方”接着执行发送.....

不知道我的想法行不行,另外我担心“把数据库中的用户写入到文件中”这个过程所花费的时间会很长,从而导致性能上会存在隐患。谢谢大家讨论我的想法,给些意见或指点!

和@舞林 同学的想法有点相似:

  • 把待发的邮件,存储到列表(Lists)中,通过lpush插入到Redis消息队列中
  • 负责发送邮件的代码中通过BRPOP依次消息队列中的内容并进行处理,如果没有新邮件则会阻塞等待直到有新的消息

这样的话不管程序死掉或者什么原因都不会千万消息丢失,同时也可以不用另外加一个定时任务


相比于写文件或者是其它的方法,Redis是目前最合适的

Redis是一个开源、支持网络、基于内存、键值对存储数据库

参考:http://zh.wikipedia.org/zh/Redis

我的做法是邮件队列,放redis,crontab每分钟发送,脚本起来的时候发现上个脚本还在跑就退出,为了避免异常,脚本最多执行110秒。做好失败的监控,没啥问题。

还有什么呢,继续吧...

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1671
14
PHP Tutorial
1276
29
C# Tutorial
1256
24
What is the significance of the session_start() function? What is the significance of the session_start() function? May 03, 2025 am 12:18 AM

session_start()iscrucialinPHPformanagingusersessions.1)Itinitiatesanewsessionifnoneexists,2)resumesanexistingsession,and3)setsasessioncookieforcontinuityacrossrequests,enablingapplicationslikeuserauthenticationandpersonalizedcontent.

Steps to add and delete fields to MySQL tables Steps to add and delete fields to MySQL tables Apr 29, 2025 pm 04:15 PM

In MySQL, add fields using ALTERTABLEtable_nameADDCOLUMNnew_columnVARCHAR(255)AFTERexisting_column, delete fields using ALTERTABLEtable_nameDROPCOLUMNcolumn_to_drop. When adding fields, you need to specify a location to optimize query performance and data structure; before deleting fields, you need to confirm that the operation is irreversible; modifying table structure using online DDL, backup data, test environment, and low-load time periods is performance optimization and best practice.

How to use MySQL functions for data processing and calculation How to use MySQL functions for data processing and calculation Apr 29, 2025 pm 04:21 PM

MySQL functions can be used for data processing and calculation. 1. Basic usage includes string processing, date calculation and mathematical operations. 2. Advanced usage involves combining multiple functions to implement complex operations. 3. Performance optimization requires avoiding the use of functions in the WHERE clause and using GROUPBY and temporary tables.

How to uninstall MySQL and clean residual files How to uninstall MySQL and clean residual files Apr 29, 2025 pm 04:03 PM

To safely and thoroughly uninstall MySQL and clean all residual files, follow the following steps: 1. Stop MySQL service; 2. Uninstall MySQL packages; 3. Clean configuration files and data directories; 4. Verify that the uninstallation is thorough.

Recommended Laravel's best expansion packs: 2024 essential tools Recommended Laravel's best expansion packs: 2024 essential tools Apr 30, 2025 pm 02:18 PM

The essential Laravel extension packages for 2024 include: 1. LaravelDebugbar, used to monitor and debug code; 2. LaravelTelescope, providing detailed application monitoring; 3. LaravelHorizon, managing Redis queue tasks. These expansion packs can improve development efficiency and application performance.

An efficient way to batch insert data in MySQL An efficient way to batch insert data in MySQL Apr 29, 2025 pm 04:18 PM

Efficient methods for batch inserting data in MySQL include: 1. Using INSERTINTO...VALUES syntax, 2. Using LOADDATAINFILE command, 3. Using transaction processing, 4. Adjust batch size, 5. Disable indexing, 6. Using INSERTIGNORE or INSERT...ONDUPLICATEKEYUPDATE, these methods can significantly improve database operation efficiency.

Composer: The Package Manager for PHP Developers Composer: The Package Manager for PHP Developers May 02, 2025 am 12:23 AM

Composer is a dependency management tool for PHP, and manages project dependencies through composer.json file. 1) parse composer.json to obtain dependency information; 2) parse dependencies to form a dependency tree; 3) download and install dependencies from Packagist to the vendor directory; 4) generate composer.lock file to lock the dependency version to ensure team consistency and project maintainability.

How to analyze the execution plan of MySQL query How to analyze the execution plan of MySQL query Apr 29, 2025 pm 04:12 PM

Use the EXPLAIN command to analyze the execution plan of MySQL queries. 1. The EXPLAIN command displays the execution plan of the query to help find performance bottlenecks. 2. The execution plan includes fields such as id, select_type, table, type, possible_keys, key, key_len, ref, rows and Extra. 3. According to the execution plan, you can optimize queries by adding indexes, avoiding full table scans, optimizing JOIN operations, and using overlay indexes.

See all articles