Hi,

What you are referring to is off-line execution of PHP. I know there are ways to do it in other web-targeted scripting languages. In PHP I'm not aware of free implementation of this functionality. I am familiar with commercial solution for that. Zend (which is where your truly works for) happens to sell a server side application which does this, among the rest. Its far from free (in any meaning), but it does just what you are looking for... :-) . For more details check here: http://www.zend.com/products/zend_platform/what_s_new (see "Job Queues" - first in the "new features" list).


Boaz.


Uri Even-Chen wrote:
Hi people,

I wrote a PHP program that sends E-mail to 121 E-mail addresses at
once [http://www.speedy.net/knesset/].  The problem is, it takes many
seconds until the program completes sending all the E-mails.  I want
to give the user an instant feedback, and send E-mails later (after
the HTML output is complete).  How do I do it?  Can I postpone the
mail sending function?  My program calls sendmail 121 times, and I
think that's the only slow part of the program.  The rest is quite
fast.  Can I call sendmail in such a way that PHP will regain control
right away?  Or alternatively, can I run another PHP script in the
background?

Below is my mail sending script.

Uri.


<?php
     $tmp_addresses_clone= $tmp_addresses;

     // Flush the output buffer.
     ob_flush(); flush();

     $tmp_count= count($tmp_addresses_clone);
     while ($tmp_count > 0)
     {
        $tmp_random= rand(0, $tmp_count - 1);

        // Open Mail Command.
        $tmp_mail_command= '/usr/sbin/sendmail -f ' . $tmp_email . '
' . $tmp_addresses_clone[$tmp_random] . ' > /dev/null 2>&1';

        $tmp_mail_file_pointer= popen($tmp_mail_command, "w");
        if ($tmp_mail_file_pointer)
        {
           // Print mail header.
           fputs($tmp_mail_file_pointer, "From: " . '=?UTF-8?B?' .
base64_encode($tmp_name) . '?=' . ' ' . '<' . $tmp_email . '>' .
"\n");
           fputs($tmp_mail_file_pointer, "To: " .
$tmp_addresses_clone[$tmp_random] . "\n");
           fputs($tmp_mail_file_pointer, "Subject: " . '=?UTF-8?B?' .
base64_encode($tmp_subject) . '?=' . "\n");
           fputs($tmp_mail_file_pointer, "MIME-Version: 1.0\n");
           fputs($tmp_mail_file_pointer, "Content-Type: text/plain;
charset=UTF-8\n");
           fputs($tmp_mail_file_pointer, "\n");

           // Print mail body.
           fputs($tmp_mail_file_pointer, $tmp_content . "\n");
           fputs($tmp_mail_file_pointer, "\n");

           // Close file.
           pclose($tmp_mail_file_pointer);
        }

        echo ($tmp_addresses_clone[$tmp_random] . '<br>' . "\n");
        $tmp_addresses_clone[$tmp_random]=
$tmp_addresses_clone[$tmp_count - 1];
        unset($tmp_addresses_clone[$tmp_count - 1]);

        // Flush the output buffer.
        ob_flush(); flush();

        $tmp_count= count($tmp_addresses_clone);
     }
?>

=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]



=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]

Reply via email to