简体   繁体   English

php&mysql订阅搜索/匹配查询

[英]php & mysql subscribe to search/matching queries

I have a real estate website that has several categories. 我有一个房地产网站,其中包含多个类别。 And i want the users to be able to subscribe via email to a certain list of offers, they can either be offers from a category ... or offers from a search list. 我希望用户能够通过电子邮件订阅某些报价列表,他们既可以是某个类别的报价,也可以是搜索列表中的报价。

How can i store they're subscription the best way in mysql ... and also how do i go about and do the notification. 我如何存储它们是mysql中最好的订阅方式...以及如何进行通知。

The best i came up with is to have a mysql sting stored in mysql table with the user ID and run a cron that takes all of that and iterates through it ... runs the cron and if there are new ads it sends an email. 我想出的最好的办法是将一个带有用户ID的mysql字符串存储在mysql表中,然后运行一个cron来获取所有这些信息并对其进行迭代...运行cron,如果有新广告,它将发送电子邮件。

But i don't think that this is the best idea, since it also means that if there is a change in database design ( ex, field names ) then all those queries would go bad. 但是我不认为这是最好的主意,因为这还意味着如果数据库设计发生变化(例如,字段名),那么所有这些查询都会变糟。

thanks a lot 非常感谢

In general you want to design your tables to be as flexible as possible to account for unexpected change. 通常,您希望将表设计为尽可能灵活,以应对意外更改。 If those fields change your queries would need to change anyway. 如果这些字段更改,则您的查询仍然需要更改。

Without having the specifics, these would be my guidelines: 没有细节,这些将是我的指导原则:

  1. Have a Users Table with the index and email 具有索引和电子邮件的用户表

  2. Have a subscription types table 有订阅类型表

  3. Have a User ID + Subscription lookup table 有一个用户ID +订阅查找表

  4. Have a pending messages table 有一个待处理的消息表

When a new update is present, collect all the emails and create a message log entry into a pending messages table. 当出现新的更新时,请收集所有电子邮件,并在未决消息表中创建一条消息日志条目。

Build your Cron to grab 20 unsent messages every few minutes and delete the message once it's sent. 构建您的Cron,使其每隔几分钟即可抓取20条未发送的消息,并在发送后将其删除。

The reason I say to iteratively send them via the CRON is because as your subscribers grow you don't want to have hundreds of emails have to go out at once and tie up your server's resources for the mail queue. 我之所以说要通过CRON反复发送邮件,是因为随着订户的增长,您不想一次发送数百封电子邮件并占用服务器资源来存放邮件队列。 You can just keep adding messages as need be and your queue will consistently send them out. 您可以仅根据需要添加消息,并且队列将始终将其发送出去。

We have been using this method pretty effectively for all our mass-emailing applications, error logging and reminder notification systems. 我们已经非常有效地将这种方法用于我们所有的大规模应用程序,错误记录和提醒通知系统。 It may not be the best solution but it's shown to be very manageable and flexible. 它可能不是最好的解决方案,但事实证明它非常易于管理和灵活。

If you change database design, you'll certainly have to fix something, that's how this world works. 如果您更改数据库设计,则肯定必须修复某些问题,这就是这个世界的工作方式。

If for some reason it's hard for you to change the cron task, you can create a stored procedure that always returns a resultset suitable for the task, and change the stored procedure instead. 如果由于某种原因您很难更改cron任务,则可以创建一个存储过程,该存储过程始终返回适合该任务的结果集,然后更改该存储过程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM