php-general Digest 20 Apr 2008 17:07:21 -0000 Issue 5415
Topics (messages 273315 through 273324):
Cron php & refresh
273315 by: Jeffrey
273316 by: Per Jessen
273318 by: Børge Holen
273319 by: Jeffrey
273320 by: Per Jessen
273321 by: Per Jessen
Re: PHP console script vs C/C++/C#
273317 by: Per Jessen
Check RAW data
273322 by: rb
273323 by: Jason Norwood-Young
273324 by: Regular email
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[EMAIL PROTECTED]
----------------------------------------------------------------------
--- Begin Message ---
I'm working on an application that includes e-mail notifications of
certain events. Because the application will have hundreds or thousands
of users, I've designed it so that e-mail notifications are saved to a
MySQL table. Then a regular cron job runs a php page to select the data
from the table, put it into a mail() command and mail.
My original vision was to have the script do about 50 mails, then pause
for a 5 seconds, do a meta refresh and run through another 50 and so on
- with experimentation in numbers as necessary. This process was set up
because I recall reading somewhere - perhaps the manual - that it is not
a good thing to run too many php mail()s in succession. Also, I worry
about php time-outs.
If you know more about PHP and 'nix than I do, you already realise the
fatal flaw here: meta refresh doesn't work on a cron job.
Question: is there an alternative? I appreciate I could use sleep()
after every 50 mails - but there would still be the time-out problem.
I've searched the manual and via Google - but haven't found anything -
possibly I am searching on the wrong terms.
Your help will be much appreciated.
Thanks,
Jeffrey
--- End Message ---
--- Begin Message ---
Jeffrey wrote:
> I'm working on an application that includes e-mail notifications of
> certain events. Because the application will have hundreds or
> thousands of users, I've designed it so that e-mail notifications are
> saved to a MySQL table. Then a regular cron job runs a php page to
> select the data from the table, put it into a mail() command and mail.
Why not just send the notification at the time of the event? (I assume
you update the database at the time of the event).
/Per Jessen, Zürich
--- End Message ---
--- Begin Message ---
On Sunday 20 April 2008 11:27:38 Jeffrey wrote:
> I'm working on an application that includes e-mail notifications of
> certain events. Because the application will have hundreds or thousands
> of users, I've designed it so that e-mail notifications are saved to a
> MySQL table. Then a regular cron job runs a php page to select the data
> from the table, put it into a mail() command and mail.
>
> My original vision was to have the script do about 50 mails, then pause
> for a 5 seconds, do a meta refresh and run through another 50 and so on
> - with experimentation in numbers as necessary. This process was set up
> because I recall reading somewhere - perhaps the manual - that it is not
> a good thing to run too many php mail()s in succession. Also, I worry
> about php time-outs.
>
> If you know more about PHP and 'nix than I do, you already realise the
> fatal flaw here: meta refresh doesn't work on a cron job.
>
> Question: is there an alternative? I appreciate I could use sleep()
> after every 50 mails - but there would still be the time-out problem.
>
> I've searched the manual and via Google - but haven't found anything -
> possibly I am searching on the wrong terms.
>
> Your help will be much appreciated.
>
> Thanks,
>
> Jeffrey
What a waste. Is the MTA operational on the server? if so, forget mailing with
php and rather use php to access the mta. It is designed to actually send
mails, lots of lots of em. If not, set it up.
I recon a cluster with hundreds of thousands of users ought to have such a
thing... a couple of blades or some of those solaris niagara 8 core nicies
doing it.
--
---
Børge Holen
http://www.arivene.net
--- End Message ---
--- Begin Message ---
Per Jessen wrote:
Jeffrey wrote:
I'm working on an application that includes e-mail notifications of
certain events. Because the application will have hundreds or
thousands of users, I've designed it so that e-mail notifications are
saved to a MySQL table. Then a regular cron job runs a php page to
select the data from the table, put it into a mail() command and mail.
Why not just send the notification at the time of the event? (I assume
you update the database at the time of the event).
/Per Jessen, Zürich
Because in my experience, several hundred e-mails takes time to send,
hence either the user leaves the page before all the mails are sent or
the page times out before all mails are sent. And if there are thousands
of e-mails, it will only get worse.
Jeffrey
--- End Message ---
--- Begin Message ---
Jeffrey wrote:
> Per Jessen wrote:
>> Jeffrey wrote:
>>
>>> I'm working on an application that includes e-mail notifications of
>>> certain events. Because the application will have hundreds or
>>> thousands of users, I've designed it so that e-mail notifications
>>> are saved to a MySQL table. Then a regular cron job runs a php page
>>> to select the data from the table, put it into a mail() command and
>>> mail.
>>
>> Why not just send the notification at the time of the event? (I
>> assume you update the database at the time of the event).
>>
>>
>> /Per Jessen, Zürich
>>
>>
> Because in my experience, several hundred e-mails takes time to send,
> hence either the user leaves the page before all the mails are sent or
> the page times out before all mails are sent. And if there are
> thousands of e-mails, it will only get worse.
Sorry, I (wrongly) assumed 1 event = 1 email.
OK, then I'd stick to what you're doing - add the event to a queue (i.e.
your database), and poll this at regular intervals. I don't think you
need to worry about the number of emails sent per interval. Just let
your PHP script generate the sendmail commands and the email-text to
stdout, then pipe that to /bin/sh.
The output generated by your script would look like this:
sendmail -oi -r <fromaddr> <toaddr> ..... <<XXX
emailhdr
emailhdr
emailtxt
emailtxt
emailtxt
XXX
sendmail -oi -r <fromaddr> <toaddr> ..... <<XXX
etc
etc
/Per Jessen, Zürich
--- End Message ---
--- Begin Message ---
Børge Holen wrote:
> Is the MTA operational on the server? if so, forget
> mailing with php and rather use php to access the mta.
Yeah, that is what mail() does - it calls sendmail.
/Per Jessen, Zürich
--- End Message ---
--- Begin Message ---
Nathan Nobbe wrote:
> umm, so whats going on here is the implicit component of the statement
> that incorporates relative or absolute performance. in terms of
> relative performance the statement is accurate; in terms of absolute
> performance, its quite inaccurate.
>
Nathan, I think we're disagreeing about the meaning of "algorithm" - an
algorithm does not have an absolute performance until it's been
implemented - in some of other language and machine.
/Per Jessen, Zürich
--- End Message ---
--- Begin Message ---
I'm getting from an external source a PNG image in raw format (encoded in
base64).
And with this code I'll echo on the screen.
------
$img=base64_decode($_POST['img']);
header("Content-type: image/png");
echo $img;
------
How can I check if the data received is a real PNG raw (and not malicious
code) ?
--- End Message ---
--- Begin Message ---
On Sun, 2008-04-20 at 15:52 +0200, rb wrote:
> I'm getting from an external source a PNG image in raw format (encoded in
> base64).
>
> And with this code I'll echo on the screen.
>
> ------
> $img=base64_decode($_POST['img']);
>
> header("Content-type: image/png");
> echo $img;
> ------
A quick way would be to try and make an image with the GD library.
Something like:
if (imagecreatefromstring($img)) {
header("Content-type:image/png");
echo $img;
}
--- End Message ---
--- Begin Message ---
On Sun, 2008-04-20 at 15:52 +0200, rb wrote:
I'm getting from an external source a PNG image in raw format (encoded in
base64).
And with this code I'll echo on the screen.
------
$img=base64_decode($_POST['img']);
header("Content-type: image/png");
echo $img;
------
A quick way would be to try and make an image with the GD library.
Something like:
if (imagecreatefromstring($img)) {
header("Content-type:image/png");
echo $img;
}
Perhaps check the image header matches the correct format for a PNG image.
--
Richard Heyes
+----------------------------------------+
| Access SSH with a Windows mapped drive |
| http://www.phpguru.org/sftpdrive |
+----------------------------------------+
--- End Message ---