473,320 Members | 1,953 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Asynchronous function call?

Hi all

There is a way to exec a function asynchronously?
I need to exec a function that is too slow but for me can be executed in the
background... there is no way???

Thanks
Aug 11 '07 #1
11 14749
On Aug 11, 12:47 pm, "Fabio" <znt.fa...@virgilio.itwrote:
Hi all

There is a way to exec a function asynchronously?
I need to exec a function that is too slow but for me can be executed in the
background... there is no way???

Thanks
I think the manual on exec() makes it pretty clear:

<http://www.php.net/exec>

"Note: If you start a program using this function and want to leave it
running in the background, you have to make sure that the output of
that program is redirected to a file or some other output stream or
else PHP will hang until the execution of the program ends."

Aug 11 '07 #2
On Aug 11, 11:47 am, "Fabio" <znt.fa...@virgilio.itwrote:
Hi all

There is a way to exec a function asynchronously?
I need to exec a function that is too slow but for me can be executed in the
background... there is no way???

Thanks
Yes and no.

PHP, being an extreamly veristile language, can be made to do many
thing with enough imagination =). First, we really need to know what
you are doing, how, and why. By you using the term 'asynchronous', I
assume you probably a good amount about programming and threads. So,
I'm not trying to assault you're judgement, but wanting to help you in
the best way.

On way to do this is to call a/multiple CLI scripts from your base PHP
script, let them process in the background, do some more things if you
would like with your "base" script, and get back to them, reading the
results later on (if you want).

Aug 11 '07 #3
"ELINTPimp" <sm*****@gmail.comha scritto nel messaggio
news:11**********************@k79g2000hse.googlegr oups.com...
PHP, being an extreamly veristile language, can be made to do many
thing with enough imagination =). First, we really need to know what
you are doing, how, and why. By you using the term 'asynchronous', I
assume you probably a good amount about programming and threads. So,
I'm not trying to assault you're judgement, but wanting to help you in
the best way.

On way to do this is to call a/multiple CLI scripts from your base PHP
script, let them process in the background, do some more things if you
would like with your "base" script, and get back to them, reading the
results later on (if you want).
Ok, I thank you and I'll explain.
In a web site page, when someone press a submit button I should exec a
mail() function to send an email to each registered user.
The execution of mail() is a little slow, so if the user list is a little
long who pressed the button need to wait to obtain the interaction with the
site.
My idea is to exec all the calls to mail() in background, so the interation
is immediate and if the mail sending use some "hidden" minutes it's not a
problem.

I hope I was clear wth my english and newbie php language :)

Thanks again.
Aug 11 '07 #4
On Aug 11, 2:41 pm, "Fabio" <znt.fa...@virgilio.itwrote:
"ELINTPimp" <smsi...@gmail.comha scritto nel messaggionews:11**********************@k79g2000hse .googlegroups.com...
PHP, being an extreamly veristile language, can be made to do many
thing with enough imagination =). First, we really need to know what
you are doing, how, and why. By you using the term 'asynchronous', I
assume you probably a good amount about programming and threads. So,
I'm not trying to assault you're judgement, but wanting to help you in
the best way.
On way to do this is to call a/multiple CLI scripts from your base PHP
script, let them process in the background, do some more things if you
would like with your "base" script, and get back to them, reading the
results later on (if you want).

Ok, I thank you and I'll explain.
In a web site page, when someone press a submit button I should exec a
mail() function to send an email to each registered user.
The execution of mail() is a little slow, so if the user list is a little
long who pressed the button need to wait to obtain the interaction with the
site.
My idea is to exec all the calls to mail() in background, so the interation
is immediate and if the mail sending use some "hidden" minutes it's not a
problem.

I hope I was clear wth my english and newbie php language :)

Thanks again.
Yes, and your idea of splitting the process to the "background" is
good. Try calling a CLI script to do the dirty work for you.
Aug 11 '07 #5
C.
On 11 Aug, 20:41, "Fabio" <znt.fa...@virgilio.itwrote:
>
Ok, I thank you and I'll explain.
In a web site page, when someone press a submit button I should exec a
mail() function to send an email to each registered user.
The execution of mail() is a little slow, so if the user list is a little
long who pressed the button need to wait to obtain the interaction with the
site.
My idea is to exec all the calls to mail() in background, so the interation
is immediate and if the mail sending use some "hidden" minutes it's not a
problem.

I hope I was clear wth my english and newbie php language :)
Try googling for PHP script and background execution - this gets asked
again and again. And its not nearly as simple as some people believe -
expect to do some testing/tinkering especially if you have any sort of
traffic volumnes.

C.
Aug 11 '07 #6
"ELINTPimp" <sm*****@gmail.comha scritto nel messaggio
news:11*********************@57g2000hsv.googlegrou ps.com...

Yes, and your idea of splitting the process to the "background" is
good. Try calling a CLI script to do the dirty work for you.
I'm really new to php... what is a CLI script?

Thanks
Aug 11 '07 #7

"C." <co************@gmail.comha scritto nel messaggio
news:11*********************@19g2000hsx.googlegrou ps.com...
>
Try googling for PHP script and background execution - this gets asked
again and again.
It's all the day I'm searching for in google... I didn't find nothing that I
understand :(
I also tryed looking in the phpBB code... don't let me tell about it...
And its not nearly as simple as some people believe -
expect to do some testing/tinkering especially if you have any sort of
traffic volumnes.
Yes, it's my fear for the future... :(

Aug 11 '07 #8
The system could also run your command for you when you use the at
command.

For example, this page launch.php calls the at command, which loads
the web page batch.php in the background:

<?

// File: launch.php

function launch($url)
{
$cmd = 'echo lynx -source ' . escapeshellarg($url) .
' | at now 2>&1';
exec($cmd, $output, $exitCode);
if ($exitCode != 0) {
$msg = "Command \"$cmd\" failed with exit code $exitCode: ";
$msg .= join("\n", $output);
trigger_error($msg, E_USER_ERROR);
return false;
}
return true;
}

$done = false;
if (isset($_GET['btn'])) {
$url = 'http://my.tld/batch.php';
$done = launch($url);
}

?>

<h3>Launch</h3>

<? if ($done) { ?>
<p>Command launched in background.</p>
<? } ?>

<form action="launch.php">
<input type=submit name=btn value=" Go ">
</form>

On Aug 11, 12:47 pm, "Fabio" <znt.fa...@virgilio.itwrote:
Hi all

There is a way to exec a function asynchronously?
I need to exec a function that is too slow but for me can be executed in the
background... there is no way???

Thanks

Aug 12 '07 #9
On 11.08.2007 21:41 Fabio wrote:
"ELINTPimp" <sm*****@gmail.comha scritto nel messaggio
news:11**********************@k79g2000hse.googlegr oups.com...
>PHP, being an extreamly veristile language, can be made to do many
thing with enough imagination =). First, we really need to know what
you are doing, how, and why. By you using the term 'asynchronous', I
assume you probably a good amount about programming and threads. So,
I'm not trying to assault you're judgement, but wanting to help you in
the best way.

On way to do this is to call a/multiple CLI scripts from your base PHP
script, let them process in the background, do some more things if you
would like with your "base" script, and get back to them, reading the
results later on (if you want).

Ok, I thank you and I'll explain.
In a web site page, when someone press a submit button I should exec a
mail() function to send an email to each registered user.
The execution of mail() is a little slow, so if the user list is a little
long who pressed the button need to wait to obtain the interaction with the
site.
My idea is to exec all the calls to mail() in background, so the interation
is immediate and if the mail sending use some "hidden" minutes it's not a
problem.

I hope I was clear wth my english and newbie php language :)

Thanks again.

I think you'd be better off having a mail sender cronjob running
independently from your web application. The application only creates a
working set for the cronjob (e.g. populates a database table or similar).

--
gosha bine

makrell ~ http://www.tagarga.com/blok/makrell
php done right ;) http://code.google.com/p/pihipi
Aug 13 '07 #10
On Aug 13, 3:51 am, gosha bine <stereof...@gmail.comwrote:
On 11.08.2007 21:41 Fabio wrote:
"ELINTPimp" <smsi...@gmail.comha scritto nel messaggio
news:11**********************@k79g2000hse.googlegr oups.com...
PHP, being an extreamly veristile language, can be made to do many
thing with enough imagination =). First, we really need to know what
you are doing, how, and why. By you using the term 'asynchronous', I
assume you probably a good amount about programming and threads. So,
I'm not trying to assault you're judgement, but wanting to help you in
the best way.
On way to do this is to call a/multiple CLI scripts from your base PHP
script, let them process in the background, do some more things if you
would like with your "base" script, and get back to them, reading the
results later on (if you want).
Ok, I thank you and I'll explain.
In a web site page, when someone press a submit button I should exec a
mail() function to send an email to each registered user.
The execution of mail() is a little slow, so if the user list is a little
long who pressed the button need to wait to obtain the interaction with the
site.
My idea is to exec all the calls to mail() in background, so the interation
is immediate and if the mail sending use some "hidden" minutes it's not a
problem.
I hope I was clear wth my english and newbie php language :)
Thanks again.

I think you'd be better off having a mail sender cronjob running
independently from your web application. The application only creates a
working set for the cronjob (e.g. populates a database table or similar).

--
gosha bine

makrell ~http://www.tagarga.com/blok/makrell
php done right ;)http://code.google.com/p/pihipi
cronjob's a good idea, especially if you don't need the mailing
executed dynamically from a web page. But it seems like he wants to
send a notification email, or something of the sort, to all the
registered users when a ticket is submitted (something like a helpdesk
system, or something of the sort). If the speed of the submission of
a email message is "time-critical" (we all know we really shouldn't
DEPEND on email on the Internet, but often times it's an important
component), perhaps a cronjob isn't really the solution. You could
set your cron to check every 5min or so, but then your delayed 5min
and there is overhead in calling the DB at least once (maybe twice to
check if there are messages pending and once to query users).

as always, it comes down to what you need for your particular
situation.

Aug 13 '07 #11
gosha bine wrote:
I think you'd be better off having a mail sender cronjob running
independently from your web application. The application only creates a
working set for the cronjob (e.g. populates a database table or similar).
Yep, but this is re-inventing the wheel.

Just need to run an SMTP daemon on localhost:25. If the PHP mail()
function is only sending to localhost for further relaying, it will
return a result very quickly. Then let the mailer daemon worry
about how long it takes to actually send the message.

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 54 days, 20:31.]

Fake Steve is Dead; Long Live Fake Bob!
http://tobyinkster.co.uk/blog/2007/08/13/fake-bob/
Aug 14 '07 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Sylwia | last post by:
Hi! I need your help... I have the following problem. I've implemented the python Windows Service which behaves like a log supervisor. If the space used by log files is bigger than a given...
0
by: Nazgul | last post by:
Hi! Sorry if I posted it twice... I need your help... I have the following problem. I've implemented the python Windows Service which behaves like a log supervisor. If the space used by log...
2
by: Chris Michael | last post by:
Hello everybody, Newbie here. I've been working on this for the last two days and I can't figure out where this problem is. I think it's something so obvious, but I can't see it! OK, firstly...
4
by: mangi03 | last post by:
Hi, I came acrosss g++ compile errors whenever I make a function call by reference and found out from the test program that compiler is treating the function argument differently when another...
39
by: Randell D. | last post by:
Folks, I'm sure this can be done legally, and not thru tricks of the trade - I hope someone can help. I'm writing a 'tool' (a function) which can be used generically in any of my projects. ...
13
by: Bern McCarty | last post by:
I have run an experiment to try to learn some things about floating point performance in managed C++. I am using Visual Studio 2003. I was hoping to get a feel for whether or not it would make...
5
by: marcsirois | last post by:
I have an SQL Query that looks like this. I simplified it for the purpose of this example, but it's still a runnable query SELECT TOP 1 FundedPositions.PositionNumber AS , (select top 1...
1
by: George2 | last post by:
Hello everyone, Such code segment is used to check whether function call or exception- handling mechanism runs out of memory first (written by Bjarne), void perverted() { try{
4
by: kp7796 | last post by:
What is synchronous function? What is asynchronous function? Unsigned char a=0; Void function (void ){ Unsigned char Flag; Flag=0 If (a==1){ Flag=1; }
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.