FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Running function in the background?
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Running function in the background? [message #176576] Tue, 10 January 2012 01:32 Go to next message
John Drako is currently offline  John Drako
Messages: 5
Registered: December 2011
Karma: 0
Junior Member
I have a site where users can download files, and I want to enable the
users to request files by email. Some of those files are big (not too
big for email attachements).

What I would like to have the user be able to do is to click on a file
and have it emailed to him, but the user shouldn't have to wait for the
emailing function to finish (tens of seconds some time) and continue
browsing and clicking on other files to email or even leave the site
confident that they'll receive the files in their email later.

So I would like the emailing functionality to happen in the background
and independent from the connection to the browser.

Is this possible? Is it doable in PHP directly?
Re: Running function in the background? [message #176577 is a reply to message #176576] Tue, 10 January 2012 01:43 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 1/9/2012 8:32 PM, John Drako wrote:
> I have a site where users can download files, and I want to enable the
> users to request files by email. Some of those files are big (not too
> big for email attachements).
>
> What I would like to have the user be able to do is to click on a file
> and have it emailed to him, but the user shouldn't have to wait for the
> emailing function to finish (tens of seconds some time) and continue
> browsing and clicking on other files to email or even leave the site
> confident that they'll receive the files in their email later.
>
> So I would like the emailing functionality to happen in the background
> and independent from the connection to the browser.
>
> Is this possible? Is it doable in PHP directly?
>

You can do it by executing a system script (i.e. bash) in the
background. But you have to have privileges to do it, which are not
normally possible on shared hosting.

What's the problem with just downloading the file? Users are used to
downloading big files (some I've had to get are > 1.8GB GPS maps).

Additionally, it might be ok for your system to send a huge file - but
may NOT be ok for the user's mail server to ACCEPT a big file.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Running function in the background? [message #176578 is a reply to message #176576] Tue, 10 January 2012 02:06 Go to previous messageGo to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
John Drako wrote:
> I have a site where users can download files, and I want to enable the
> users to request files by email. Some of those files are big (not too
> big for email attachements).
>
> What I would like to have the user be able to do is to click on a file
> and have it emailed to him, but the user shouldn't have to wait for the
> emailing function to finish (tens of seconds some time) and continue
> browsing and clicking on other files to email or even leave the site
> confident that they'll receive the files in their email later.
>
> So I would like the emailing functionality to happen in the background
> and independent from the connection to the browser.
>
> Is this possible? Is it doable in PHP directly?
>
it happens anyway.

the 'program running in the background' is the mailer daemon.

When you invoke php mail() function all that does is validate the
addresses and queue the e-mail.

sendmail (or whatever) then forks to do the actual sending as a separate
process. (or not if you use the queue only functionality: In that case
the mail will get sent in the next queue run - maybe every hour typically)



Now making up an external file as the message body is trivial, but
making it an attachment is not.


But even fairly large attachments - 5-10MB - is not too hard. And won't
tie up php too much o for too long.
Re: Running function in the background? [message #176579 is a reply to message #176576] Tue, 10 January 2012 02:50 Go to previous messageGo to next message
Michael Joel is currently offline  Michael Joel
Messages: 42
Registered: October 2011
Karma: 0
Member
On Mon, 9 Jan 2012 20:32:43 -0500, John Drako
<jbravo556(at)gmail(dot)removethis(dot)com> wrote:

> I have a site where users can download files, and I want to enable the
> users to request files by email. Some of those files are big (not too
> big for email attachements).
>
> What I would like to have the user be able to do is to click on a file
> and have it emailed to him, but the user shouldn't have to wait for the
> emailing function to finish (tens of seconds some time) and continue
> browsing and clicking on other files to email or even leave the site
> confident that they'll receive the files in their email later.
>
> So I would like the emailing functionality to happen in the background
> and independent from the connection to the browser.
>
> Is this possible? Is it doable in PHP directly?

Just an idea - if it sounds dumb just ignore me :)

If nothing else works better. Instead of needing privileges do run
system scrips - couldn't you create a cron job for a PHP script that
sends emails to all records in a database?

When the user clicks the link it simply adds their email address and
fiel to email to the database. When the cron job runs it sends out an
email with the files linked with it.

just a quick thought
Mike
Re: Running function in the background? [message #176581 is a reply to message #176576] Tue, 10 January 2012 10:03 Go to previous messageGo to next message
Captain Paralytic is currently offline  Captain Paralytic
Messages: 204
Registered: September 2010
Karma: 0
Senior Member
On Jan 10, 1:32 am, John Drako <jbravo...@gmail.removethis.com> wrote:
> confident that they'll receive the files in their email later.

as has been pointed out, it is this requirement that may well not be
met by email, particularly in the case of very large files.
Re: Running function in the background? [message #176584 is a reply to message #176579] Tue, 10 January 2012 10:50 Go to previous messageGo to next message
Luuk is currently offline  Luuk
Messages: 329
Registered: September 2010
Karma: 0
Senior Member
On 10-01-2012 03:50, Michael Joel wrote:
> On Mon, 9 Jan 2012 20:32:43 -0500, John Drako
> <jbravo556(at)gmail(dot)removethis(dot)com> wrote:
>
>> I have a site where users can download files, and I want to enable the
>> users to request files by email. Some of those files are big (not too
>> big for email attachements).
>>
>> What I would like to have the user be able to do is to click on a file
>> and have it emailed to him, but the user shouldn't have to wait for the
>> emailing function to finish (tens of seconds some time) and continue
>> browsing and clicking on other files to email or even leave the site
>> confident that they'll receive the files in their email later.
>>
>> So I would like the emailing functionality to happen in the background
>> and independent from the connection to the browser.
>>
>> Is this possible? Is it doable in PHP directly?
>
> Just an idea - if it sounds dumb just ignore me :)
>
> If nothing else works better. Instead of needing privileges do run
> system scrips - couldn't you create a cron job for a PHP script that
> sends emails to all records in a database?
>
> When the user clicks the link it simply adds their email address and
> fiel to email to the database. When the cron job runs it sends out an
> email with the files linked with it.
>
> just a quick thought
> Mike

i like this solution,
but i cannot find the 'i like'-button ;)

--
Luuk
Re: Running function in the background? [message #176590 is a reply to message #176579] Tue, 10 January 2012 12:52 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 1/9/2012 9:50 PM, Michael Joel wrote:
> On Mon, 9 Jan 2012 20:32:43 -0500, John Drako
> <jbravo556(at)gmail(dot)removethis(dot)com> wrote:
>
>> I have a site where users can download files, and I want to enable the
>> users to request files by email. Some of those files are big (not too
>> big for email attachements).
>>
>> What I would like to have the user be able to do is to click on a file
>> and have it emailed to him, but the user shouldn't have to wait for the
>> emailing function to finish (tens of seconds some time) and continue
>> browsing and clicking on other files to email or even leave the site
>> confident that they'll receive the files in their email later.
>>
>> So I would like the emailing functionality to happen in the background
>> and independent from the connection to the browser.
>>
>> Is this possible? Is it doable in PHP directly?
>
> Just an idea - if it sounds dumb just ignore me :)
>
> If nothing else works better. Instead of needing privileges do run
> system scrips - couldn't you create a cron job for a PHP script that
> sends emails to all records in a database?
>
> When the user clicks the link it simply adds their email address and
> fiel to email to the database. When the cron job runs it sends out an
> email with the files linked with it.
>
> just a quick thought
> Mike

A good idea if you can create cron jobs. However, it has its down
sides, also. Either you have to run the cron job quite often, taking
system resources when there is no work to do, or the user has to wait a
while before receiving the file.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Running function in the background? [message #176594 is a reply to message #176576] Tue, 10 January 2012 16:29 Go to previous messageGo to next message
M. Strobel is currently offline  M. Strobel
Messages: 386
Registered: December 2011
Karma: 0
Senior Member
Am 10.01.2012 02:32, schrieb John Drako:
> I have a site where users can download files, and I want to enable the
> users to request files by email. Some of those files are big (not too
> big for email attachements).
>
> What I would like to have the user be able to do is to click on a file
> and have it emailed to him, but the user shouldn't have to wait for the
> emailing function to finish (tens of seconds some time) and continue
> browsing and clicking on other files to email or even leave the site
> confident that they'll receive the files in their email later.
>
> So I would like the emailing functionality to happen in the background
> and independent from the connection to the browser.
>
> Is this possible? Is it doable in PHP directly?
>
Damn good question.

As to do it in PHP directly I find
http://stackoverflow.com/questions/317392/is-process-forking-in-php-apache- a-good-idea
with links to other questions of this type.

I never did forking in the web server because I consider it
dangerous, it can kill or hang it or send it into a loop.

I did it like Mike suggested, with cron-jobs running every 10
minutes, and even with my own daemon "watching" a job file. For
shared hosting mostly not doable..

/Str.
Re: Running function in the background? [message #176595 is a reply to message #176594] Tue, 10 January 2012 16:39 Go to previous messageGo to next message
M. Strobel is currently offline  M. Strobel
Messages: 386
Registered: December 2011
Karma: 0
Senior Member
Am 10.01.2012 17:29, schrieb M. Strobel:
> Am 10.01.2012 02:32, schrieb John Drako:
>> I have a site where users can download files, and I want to enable the
>> users to request files by email. Some of those files are big (not too
>> big for email attachements).
>>
>> What I would like to have the user be able to do is to click on a file
>> and have it emailed to him, but the user shouldn't have to wait for the
>> emailing function to finish (tens of seconds some time) and continue
>> browsing and clicking on other files to email or even leave the site
>> confident that they'll receive the files in their email later.
>>
>> So I would like the emailing functionality to happen in the background
>> and independent from the connection to the browser.
>>
>> Is this possible? Is it doable in PHP directly?
>>
> Damn good question.
>
> As to do it in PHP directly I find
> http://stackoverflow.com/questions/317392/is-process-forking-in-php-apache- a-good-idea
> with links to other questions of this type.
>
> I never did forking in the web server because I consider it
> dangerous, it can kill or hang it or send it into a loop.
>
> I did it like Mike suggested, with cron-jobs running every 10
> minutes, and even with my own daemon "watching" a job file. For
> shared hosting mostly not doable..
>
> /Str.

Addition:

If the at command works okay in your server you can schedule jobs
in your script. I do it in a cgi script calling a shell script,
and this does

echo /usr/local/bin/webblock remove $2 | /usr/bin/at now + 5
minutes 2>/dev/null
Re: Running function in the background? [message #176608 is a reply to message #176581] Wed, 11 January 2012 13:40 Go to previous message
John Drako is currently offline  John Drako
Messages: 5
Registered: December 2011
Karma: 0
Junior Member
On Tue, 10 Jan 2012 05:03:34 -0500, Captain Paralytic wrote
(in article
<ac12a4d2-7ef6-4468-a6d6-8ba2ee5b0381(at)k29g2000vbl(dot)googlegroups(dot)com>):

> On Jan 10, 1:32 am, John Drako <jbravo...@gmail.removethis.com> wrote:
>> confident that they'll receive the files in their email later.
>
> as has been pointed out, it is this requirement that may well not be
> met by email, particularly in the case of very large files.

Thanks everybody for the feedback.

The site handles ebooks and emailing ebooks is a way to overcome a bug
in the Kindle Fire to open .mobi files downloaded directly onto it from
sources other than Amazon.

After careful consideration and analysis of the user base needs, I've
opted to not seek a solution to run it in the background. The few
readers that need this know that they'll have to wait.

So I implemented it as normal with PHPMailer. As I control the server
farm as well as the contents engine, I could have executed any solution,
but it wasn't worth the effort in the end.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: form - file - sumple question
Next Topic: Lilupophilupop
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Nov 22 09:21:28 GMT 2024

Total time taken to generate the page: 0.01883 seconds