Göndermek için e-posta zamanlama nasıl

5 Cevap php

PHP kullanarak, ben hatırlatma günün belirli saatlerinde tetikler ile bekleyen görevleri arıyorum benim DB geçer bir sorgu var. Ben her 10 dakika çalışır ve sonraki 10 dakika içinde çalacağı "remind_me" alanına sahip herhangi bir satır için DB denetleyen bir cronjob var. Bir şey bulmak yoksa, ne görev bilgileri içeren bir e-posta Sıraya iyi yolu nedir?

Ben mesaj kuyruğu sistemi çeşit gerekir sanırım, ama nasıl e-posta parçası çalışır? Ben kuyruk sistemini kontrol etmek her dakika çalışan başka cronjob gerekecek mi?

5 Cevap

Bir posta kuyruğu sistemi yapmak istiyorsanız ben size PEAR::Mail_Queue bir göz ve ilişkili öğretici öneririm.

Sen 10minute komut çalıştırdığınızda mail sıraya, ve posta kuyruk bir cron job ile her 10 dakikada boşalttı olması mümkün olacaktır. Ayrıca posta sırası her dakika boşaltılmasını ve uygulamak bir soru postada kuyruğunda zaman 'önce göndermek yok'.

Bir kuyruk sistemi için gereksinimini ortadan kaldırır, hangi alternatif bir hatırlatma, son on dakikada nedeniyle öğeler için her dakika kontrol çek komut çalıştırabilir ve anında posta gönderebilirsiniz.

(Eğer herhangi bir kaçırmayın ve iki uyarılar göndermek kalmamak) Bu son uyarı gönderdi zaman bir rekor tarafından uygulanan olabilir

Umut olur.

I just very recently wrote my own solution to a very similar problem using PHP and MySQL.
Essentially: cron job runs a script at a set interval, that script checks the database for pending jobs, runs them, and deletes the jobs.

This is simply what I needed to do, but it could be modified to work for time intervals.
I wrote a separate PHP script that runs the actual job (a newsletter system) to make this automation a bit more useful. That is, I can run whatever command I want from it, I accomplish this by storing the name of the actual command and its arguments in the automator script.

exec("~/scripts/{$row['command']} {$row['args']}");

benim bülten komut daha kullanışlı hale getirmek için veritabanına argümanları saklamak için izin verir. Sen argümanlar kapmak için array $ argv kullanmak, $ argv [0] argümanlar sırayla takip komut adıdır.

Ben kronolojik sırayla sıralar veritabanında ayrı bir tabloda tüm bülten bilgi depolamak. Diğer önemli, alanlar e-postanın konu ve vücut vardır. Bülten numarası ve abone numarası (veya tüm): Ben o zaman sadece ben istiyorum tam olarak ne yapmak newsletter.php için iki argüman geçmek.

Süre için test (10 dakika önce) böyle bir şey (ben daha kolay anlamak için yapma uğruna basitleştirilmiş aşırı) ile yapılabilir:

date_default_timezone_set('America/Denver');
$month=;//without leading zeros
$day=;//without leading zeros
$hour=;//24 hour without leading zeros
$min=;//needs leading zeros
if($month==date(n) and $day==date(j)){
    if($hour==date(G)){
        if(($min-date(i))<=10){
            //run command
        }
    }elseif(($hour-1)==date(g)){
        if(($min-date(i))<=(-50)){
            //run command
        }
    }
}

You will want to change the timezone to your own, and pull the date and time information from the DB in some way.
The second part of the script (to run commands scheduled in the first 9 minutes of an hour) is untested but the first part I quickly tested it just now.
Hope this helps.

Biz benzer bir sistem (bu bir ASP.NET uygulaması yani biz bir iç zamanlayıcı kullanarak bu çalıştırmak için hizmetleri var ... ama ayrıntılar önemsizdir) var. Biz e-posta veri gönderilmesini içeren bir büyük mesaj kuyruğu tablo var, bir adresi ve konu satırında (gerçek e-posta şablonları oluşturulur) için. Bizim sistem çalışır şekilde bir satır doldurulur sonra biz hemen tüm e-postaları bekleyen toplar ve gönderir bir gönderme görevi tetikleyebilir olmasıdır. Onlara 3 kez göndermeyi dener ve başarısız eğer başarısız bir yeniden gönderilen devlet konur. Biz herhangi bir başarısız görevleri (onlar yüzünden bir ağ sorunu zaman% 99 ise şey çok nadiren başarısız) süpürüyor her 5 dakika çalışır işi gibi bir cron var.

Ne kadar sıklıkla bir e-posta göndermek istiyorsunuz? Bu oluşumu (bu sizin mevcut cronjob, yani her 10 dakikada tarafından keşfedilir dakika) Eğer, hatırlatmak-me bayrak arar script bunu yapabilir:

1 -, bayrak bir dizi bulundu, her satır için bir başvuru ekleyin örneğin

$reminders = array(1, 3, 212);

Dizideki her eleman burada "görevleri" kullanılan görevleri tablonun bir birincil anahtarı başvuruyor.

2 - veritabanı arama tamamlandıktan sonra, $ hatırlatmalar boş olup olmadığını görmek ve sonra gibi bir sorgu çalıştırmak

$query = "SELECT * FROM tasks WHERE id = '".implode(',', $reminders)."'";

tüm görev özgü verileri almak için

3 - mail kullanarak bu veri ile kendiniz için bir e-posta gönderin.

Bu sizin için ne aradığını oldu?

PHP solution

Ben biraz daha fazla sorun hakkında düşünce var ve bu benim geldiğim PHP çözümdür.

#!/opt/lamp/bin/php is the path to my php interpreter. You should change it to your path or just run it with php -f scheduler.php

scheduler.php

#!/opt/lampp/bin/php
<?php
// For testing purpose I set this to 5 seconds. You should set it to 600.
$time = 5;

while (true) {
    /*  
    let's assume you store the emails scheduled from the database in this
    in memory array.
    */
    $array = array( 
        "Message to run last", #message which is scheduled last.
        "Message to run after first message",
        "Message to run immediately", #message which is scheduled first.
    );

    $message = array_pop($array);    
    while ($message != NULL) {
            echo $message . "\r\n";
            /* 
            For testing purpose I am just simply echoing out messages.
            In here you should sent mails using for exmample
            http://php.net/manual/en/function.mail.php
            */
            $message = array_pop($array); // Get next message.
    }

    /*
    sleep $time. This is the "cron" part of your problem.
    */
    sleep($time); 
}

Sen ne yaptığını görmek için bir Bash komut dosyası içinde bu komut dosyasını çalıştırmanız gerekir. Ayrıca kod oldukça iyi belgelenmiş oldu. Betik (arka planda) sonsuza kadar çalıştırmak gerekir.

Java Solution

This also isn't a PHP only solution, ama bu ben ile geldi PHP çözümü daha iyi ölçek düşünüyorum. Ben hala bu çalışıyorum, ama ben bugüne kadar geldi ne gibi.

Google App Engine Solution

I know this is not a PHP solution, but when you can not install a message queue I think Google App Engine is the best solution. When I saw this video introduction from Brett Slatkin to google app engine using the Python SDK I was sold to Google App engine. It will only take 10 minutes of your time and you will learn how to create a basic guestbook and deploy it to the cloud. Below if interested I will try to explain which pieces you need to do this on Google's App Engine.


I guess I'll need some sort of message queue system

Belki google app motorunun taskqueue görevi qeueu için kullanabilirsiniz. Taskqueue bile belirli bir zamanda çalışacak şekilde ayarlayabilirsiniz bir eta hangi vardır. Google App motor cömert bir free quota vardır. Her gün ücretsiz olarak göreve 100,000 sıraları ekleyebilirsiniz.

ama nasıl e-posta bölümü iş

Bunun için google app motoru kullanacak. Google app engine 'mail servisini kullanabilirsiniz. Ayrıca (2000 alıcıları bir gün) bir cömertçe ücretsiz bir kota vardır. Ben sadece mesaj göndermek için kuyruktan posta API cal tavsiye ederiz.