Re: Can a PHP script run in the background?

2007-03-11 Thread Chaim Keren Tzion
Great script! I just used it with the following text:

Subject: Please Do Something for Polard Today

Please do something for Polard today.

You're welcome,
Chaim


On Wednesday 07 March 2007 12:51, 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.
>
>
>$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] . '' . "\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]

-- 
Chaim Keren Tzion
[EMAIL PROTECTED]
+972-(0)54-465-2983
+972-(0)2-53-53-363

ICQ: 2076934
AIM: lifelionzionray
MSN: [EMAIL PROTECTED]
Yahoo: chakatz
Skype: lionslife

=
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]



Re: Can a PHP script run in the background?

2007-03-08 Thread Peter



On Thu, 8 Mar 2007, Uri Even-Chen wrote:


On 3/8/07, Peter <[EMAIL PROTECTED]> wrote:

use dhtml to fake the 'sending process'


I'm not that familiar with dhtml.  How do I do it?


Use Javascript to show an animation of 'sending ... sending ... sent1'

Peter

=
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]



Re: Can a PHP script run in the background?

2007-03-08 Thread Uri Even-Chen

On 3/8/07, Peter <[EMAIL PROTECTED]> wrote:

use dhtml to fake the 'sending process'


I'm not that familiar with dhtml.  How do I do it?

Uri.

=
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]



Re: Can a PHP script run in the background?

2007-03-08 Thread Peter


On Thu, 8 Mar 2007, Uri Even-Chen wrote:


presses "send", but I don't want the user to wait before he sees the
confirmation message.  Maybe I will just move the PHP script to the
end of the file, after the  tag.  Will it work?


use dhtml to fake the 'sending process'

P

=
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]



Re: Can a PHP script run in the background?

2007-03-07 Thread Uri Even-Chen

I was wondering, maybe I can just add the & sign to the sendmail
command line?  Will it work?  If this line is executed 121 times from
my script?

Here is the line:
$tmp_mail_command= '/usr/sbin/sendmail -f ' . $tmp_email . '
' . $tmp_addresses_clone[$tmp_random] . ' > /dev/null 2>&1';

Uri.

=
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]



Re: Can a PHP script run in the background?

2007-03-07 Thread Uri Even-Chen

On 3/7/07, Boaz Rymland <[EMAIL PROTECTED]> wrote:

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).


Thanks for the feedback.  Actually, I'm looking for something free
(beer), free (speech) and easy to implement.  It's just a free service
I give to the public.  I know it can be used to spam knesset members,
but maybe this will convince them to legally ban spam :-) I could also
set up a mail alias that will forward mail to all the 121 addresses
(includng [EMAIL PROTECTED]), but I want each MK to be the only
recipient to a "personal" message sent to him.  Maybe I should have
impleneted it using a procmail script.  But I don't know procmail that
well.  Do you?  And besides, if I set up a mail alias and spam is sent
to it, then they will really receive a lot of spam from my server.

I don't think my server will be marked as spammer in RBL for this
little feature... but who knows?  I can always remove it if I want to.

But on the other hand, I might get phone calls from angry police
officers asking me to reveal IP addresses of users who used it to send
anonymous mail.  I already received such calls in the past.  I never
revealed any information, except once, when they came to my house with
a court order.  But I regret it.  Next time I will not reveal
anything.  I don't track anything anyway (except what the server does
automatically.  And please, government people, pretend you haven't
read that!)

On 3/7/07, Ira Abramov <[EMAIL PROTECTED]> wrote:

What happens when spammers start using your little script? or maybe just
stupid kids start sending curses "just to see if it works"? What if your
user wants to send just the MKs interested in green energy or just the
ones involved in fighting traffic dangers?

you wrote a primitive little webform that will get your website either
blocked or sued faster than you can speed-dial your lawyer.


You are right, it might be used by spammers who want to specifically
harass knesset members (as opposed to spammers who want to make
money).  But I don't mind.  I'm not doing anything illegal here.  I
also decided to allow anonymous mailing (forged address), since SMTP
allows it too.  The sender's E-mail address is checked to be legal,
but it can be [EMAIL PROTECTED] as far as I'm concerned.  I
don't mind.  I don't think knesset members will sue me I'm just
the service provider here (not the sender).


You put it in a queue, tell the user you are sending her a confirmation
request. and if the Email checks out you take care of sending the emails
and at the end of the run send another email to tell them it was sent.


Sounds too complicated.  I want to send it immediately after the user
presses "send", but I don't want the user to wait before he sees the
confirmation message.  Maybe I will just move the PHP script to the
end of the file, after the  tag.  Will it work?

Uri.

=
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]



Re: Can a PHP script run in the background?

2007-03-07 Thread Boaz Rymland

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.


 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] . '' . "\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]



Re: Can a PHP script run in the background?

2007-03-07 Thread Hetz Ben Hamo

Hi Uri,

Without entering any political fight with you here on this list (or
elsewhere) - Your script to send emails to MK from your site, WILL get
your site's mail blocked and marked as SPAM (as well as being marked
as spammer in RBL etc...)

Please note: the guys in the goverment who do monitor the mail servers
for the goverment are also subscribed to this mailing list (and no,
I'm not one of them).

Thanks,
Hetz

On 3/7/07, Uri Even-Chen <[EMAIL PROTECTED]> 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.


 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] . '' . "\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]





--
Skepticism is the lazy person's default position.
Visit my blog (hebrew) for things that (sometimes) matter:
http://wp.dad-answers.com

=
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]



Re: Can a PHP script run in the background?

2007-03-07 Thread Ira Abramov
Quoting Uri Even-Chen, from the post of Wed, 07 Mar:
> 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

What happens when spammers start using your little script? or maybe just
stupid kids start sending curses "just to see if it works"? What if your
user wants to send just the MKs interested in green energy or just the
ones involved in fighting traffic dangers?

you wrote a primitive little webform that will get your website either
blocked or sued faster than you can speed-dial your lawyer. I suggest
you start small - first have an Email confirmation mechanism to make
sure your sender is not an anonymous spammer. then maybe have humans
going over the letters before you send them out to make sure you won't
shoot yourself in the foot. Then maybe sendi them just to members of
specific  groups or parties seperately.

from my short experiance of 10 years maintaining dynamic websites,
leaving an open form like this that sends mail to third parties is
inviting trouble. a better idea is list all the addresses as plain text,
not mailto: links even, in usefull groups. Have your users copy the
bunch they want to harass to their mail program and bomb the knesset
with their own account. you do NOT want to be in the middle of this when
the sh*t hits the fan (and it will)

> 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?  

You put it in a queue, tell the user you are sending her a confirmation
request. and if the Email checks out you take care of sending the emails
and at the end of the run send another email to tell them it was sent.


-- 
Hong Kong action star
Ira Abramov
http://ira.abramov.org/email/

=
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]



Re: Can a PHP script run in the background?

2007-03-07 Thread Shlomi Fish

On 3/7/07, Ori Idan <[EMAIL PROTECTED]> wrote:

I think the best way is not to send by PHP at all but to set up a mailing
list such as Majordomo or mailman and then use PHP to send to one address,
the list address.



One can also set up an alias that sends email to several recipients at
the mail server level. Some mail servers also support reading the
recipients lists from an LDAP or SQL database.

Regards,

   Shlomi Fish


--
Ori Idan



 On 3/7/07, Uri Even-Chen <[EMAIL PROTECTED]> 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.
>
>
>$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] . ''
. "\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]
>
>





--
--
Shlomi Fish http://www.shlomifish.org/

If his programming is anything like his philosophising, he
would find 10 imaginary bugs in the "Hello World" program.

=
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]



Re: Can a PHP script run in the background?

2007-03-07 Thread Sagi Bashari

On 3/7/07, Uri Even-Chen <[EMAIL PROTECTED]> 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?




PHP can also run from command line, using the /usr/bin/php CLI.

So instead of running the script from the browser you can make it run from a
regular shell where the running time is not much of an issue.

Once you do that you can also run it from cron.

Here we have a mailing list manager in PHP that works this way:
1. The site administrator composes the email in a web interface.
2. The message is inserted into a database
3. Once an hour, a PHP script is ran through cron. It selects all the new
messages from the database and mails them.


Uri.



Sagi


Re: Can a PHP script run in the background?

2007-03-07 Thread Ori Idan

I think the best way is not to send by PHP at all but to set up a mailing
list such as Majordomo or mailman and then use PHP to send to one address,
the list address.

--
Ori Idan


On 3/7/07, Uri Even-Chen <[EMAIL PROTECTED]> 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.


 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] . '' . "\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]




Re: Can a PHP script run in the background?

2007-03-07 Thread Geoffrey S. Mendelson
On Wed, Mar 07, 2007 at 12:51:42PM +0200, Uri Even-Chen wrote:
> I wrote a PHP program that sends E-mail to 121 E-mail addresses at
> once [http://www.speedy.net/knesset/]. 

I'm wondering if there is another way to do this. For example, there may be
a public email alias at the Knesset that does this for you. You should
contact the mailroom and ask.

They may have other services such as you send them one fax, they
photocopy it and deliver it to a distribution list, or all of the MKs.
They may accept letters (on paper) in one envelope and distribute them
for you. 

Sending out 120 emails at once, or in very close proximity could easily
get you banned due to SPAMing. I understand that you are doing this for
what you see as a good purpose, but someone else might not.

I'll tell you as story. In the U.S. one state legislature passed a law
banning the sending of FAX SPAM. It went to the governer who had the option
of signing it or vetoing it. Several direct FAX marketing associations 
notified their members and suggested they send him a FAX protesting it.
Faxes came in from all over the U.S. and tied up his FAX machine for three
days. You can guess what he did.



-- 
Geoffrey S. Mendelson, Jerusalem, Israel [EMAIL PROTECTED]  N3OWJ/4X1GM
IL Voice: (07)-7424-1667  Fax ONLY: 972-2-648-1443 U.S. Voice: 1-215-821-1838 
Visit my 'blog at http://geoffstechno.livejournal.com/

=
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]



Can a PHP script run in the background?

2007-03-07 Thread Uri Even-Chen

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.


 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] . '' . "\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]