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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
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)

mysql whether to change table lock table mysql whether to change table lock table Apr 08, 2025 pm 05:06 PM

When MySQL modifys table structure, metadata locks are usually used, which may cause the table to be locked. To reduce the impact of locks, the following measures can be taken: 1. Keep tables available with online DDL; 2. Perform complex modifications in batches; 3. Operate during small or off-peak periods; 4. Use PT-OSC tools to achieve finer control.

RDS MySQL integration with Redshift zero ETL RDS MySQL integration with Redshift zero ETL Apr 08, 2025 pm 07:06 PM

Data Integration Simplification: AmazonRDSMySQL and Redshift's zero ETL integration Efficient data integration is at the heart of a data-driven organization. Traditional ETL (extract, convert, load) processes are complex and time-consuming, especially when integrating databases (such as AmazonRDSMySQL) with data warehouses (such as Redshift). However, AWS provides zero ETL integration solutions that have completely changed this situation, providing a simplified, near-real-time solution for data migration from RDSMySQL to Redshift. This article will dive into RDSMySQL zero ETL integration with Redshift, explaining how it works and the advantages it brings to data engineers and developers.

Query optimization in MySQL is essential for improving database performance, especially when dealing with large data sets Query optimization in MySQL is essential for improving database performance, especially when dealing with large data sets Apr 08, 2025 pm 07:12 PM

1. Use the correct index to speed up data retrieval by reducing the amount of data scanned select*frommployeeswherelast_name='smith'; if you look up a column of a table multiple times, create an index for that column. If you or your app needs data from multiple columns according to the criteria, create a composite index 2. Avoid select * only those required columns, if you select all unwanted columns, this will only consume more server memory and cause the server to slow down at high load or frequency times For example, your table contains columns such as created_at and updated_at and timestamps, and then avoid selecting * because they do not require inefficient query se

The primary key of mysql can be null The primary key of mysql can be null Apr 08, 2025 pm 03:03 PM

The MySQL primary key cannot be empty because the primary key is a key attribute that uniquely identifies each row in the database. If the primary key can be empty, the record cannot be uniquely identifies, which will lead to data confusion. When using self-incremental integer columns or UUIDs as primary keys, you should consider factors such as efficiency and space occupancy and choose an appropriate solution.

Can mysql run on android Can mysql run on android Apr 08, 2025 pm 05:03 PM

MySQL cannot run directly on Android, but it can be implemented indirectly by using the following methods: using the lightweight database SQLite, which is built on the Android system, does not require a separate server, and has a small resource usage, which is very suitable for mobile device applications. Remotely connect to the MySQL server and connect to the MySQL database on the remote server through the network for data reading and writing, but there are disadvantages such as strong network dependencies, security issues and server costs.

Can mysql return json Can mysql return json Apr 08, 2025 pm 03:09 PM

MySQL can return JSON data. The JSON_EXTRACT function extracts field values. For complex queries, you can consider using the WHERE clause to filter JSON data, but pay attention to its performance impact. MySQL's support for JSON is constantly increasing, and it is recommended to pay attention to the latest version and features.

Can mysql handle multiple connections Can mysql handle multiple connections Apr 08, 2025 pm 03:51 PM

MySQL can handle multiple concurrent connections and use multi-threading/multi-processing to assign independent execution environments to each client request to ensure that they are not disturbed. However, the number of concurrent connections is affected by system resources, MySQL configuration, query performance, storage engine and network environment. Optimization requires consideration of many factors such as code level (writing efficient SQL), configuration level (adjusting max_connections), hardware level (improving server configuration).

Do mysql need to pay Do mysql need to pay Apr 08, 2025 pm 05:36 PM

MySQL has a free community version and a paid enterprise version. The community version can be used and modified for free, but the support is limited and is suitable for applications with low stability requirements and strong technical capabilities. The Enterprise Edition provides comprehensive commercial support for applications that require a stable, reliable, high-performance database and willing to pay for support. Factors considered when choosing a version include application criticality, budgeting, and technical skills. There is no perfect option, only the most suitable option, and you need to choose carefully according to the specific situation.

See all articles