Multithreading in PHP

Multithreading in PHP

am 17.03.2009 14:14:46 von Manoj Singh

--0003255760b2da594c0465505990
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

Hi Guys,

I am creating a page which submits the form through Ajax request & the
submitted page is sending the mails to n number of users. Now until the mail
sends or the page process completed the end user has to wait.

Is it possible that server sends the response to the client & then start
processing so that the client doesn't have to wait for the server response.

Please suggest.

Regards,
Manoj

--0003255760b2da594c0465505990--

Re: Multithreading in PHP

am 17.03.2009 14:31:29 von torokalpar

2009/3/17 Manoj Singh :
> Hi Guys,
>
> I am creating a page which submits the form through Ajax request & the
> submitted page is sending the mails to n number of users. Now until the mail
> sends or the page process completed the end user has to wait.
>
> Is it possible that server sends the response to the client & then start
> processing so that the client doesn't have to wait for the server response.
>
> Please suggest.
>
> Regards,
> Manoj
>
Since you are using Ajax requests, which by their nature are
asynchronous , your user won't have to wait. You can write some JS
code to let him know that the request was sent, and just let the ajax
call run in the background. On the server side make sure to ignore
user abort, just in case the user navigates away.


--
Alpar Torok

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Multithreading in PHP

am 17.03.2009 14:39:10 von Manoj Singh

--0003255749be1c973c046550b187
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Hi Alpar,

Thanks for reply.

Actually the form is submitted through ajax request and the validation is
checking on the server side. So if any error occurs on submission of form,
then we are displaying the errors to the user. And is there is no error,
then the submitted page started processing. So here client has to wait unti=
l
the page process completed or not. What i want here if possible, after
validating the user input server sends the thanks response to the client so
that cleint doesn't has to wait, then the server starts the processing.
Please suggest if it is possible.

Regards,
Manoj



On Tue, Mar 17, 2009 at 7:01 PM, Alp=E1r Török w=
rote:

> 2009/3/17 Manoj Singh :
> > Hi Guys,
> >
> > I am creating a page which submits the form through Ajax request & the
> > submitted page is sending the mails to n number of users. Now until the
> mail
> > sends or the page process completed the end user has to wait.
> >
> > Is it possible that server sends the response to the client & then star=
t
> > processing so that the client doesn't have to wait for the server
> response.
> >
> > Please suggest.
> >
> > Regards,
> > Manoj
> >
> Since you are using Ajax requests, which by their nature are
> asynchronous , your user won't have to wait. You can write some JS
> code to let him know that the request was sent, and just let the ajax
> call run in the background. On the server side make sure to ignore
> user abort, just in case the user navigates away.
>
>
> --
> Alpar Torok
>

--0003255749be1c973c046550b187--

Re: Multithreading in PHP

am 17.03.2009 14:46:26 von joao

My suggestion is that you can start a second ajax as soon as the response
about validating data is returned to process everithing you need and so your
user wont wait until the process is finished.

João Cândido

"Manoj Singh" escreveu na mensagem
news:3859a530903170639m6c2af2b2s941446a31103cf2a@mail.gmail. com...
Hi Alpar,

Thanks for reply.

Actually the form is submitted through ajax request and the validation is
checking on the server side. So if any error occurs on submission of form,
then we are displaying the errors to the user. And is there is no error,
then the submitted page started processing. So here client has to wait until
the page process completed or not. What i want here if possible, after
validating the user input server sends the thanks response to the client so
that cleint doesn't has to wait, then the server starts the processing.
Please suggest if it is possible.

Regards,
Manoj



On Tue, Mar 17, 2009 at 7:01 PM, Alpár Török wrote:

> 2009/3/17 Manoj Singh :
> > Hi Guys,
> >
> > I am creating a page which submits the form through Ajax request & the
> > submitted page is sending the mails to n number of users. Now until the
> mail
> > sends or the page process completed the end user has to wait.
> >
> > Is it possible that server sends the response to the client & then start
> > processing so that the client doesn't have to wait for the server
> response.
> >
> > Please suggest.
> >
> > Regards,
> > Manoj
> >
> Since you are using Ajax requests, which by their nature are
> asynchronous , your user won't have to wait. You can write some JS
> code to let him know that the request was sent, and just let the ajax
> call run in the background. On the server side make sure to ignore
> user abort, just in case the user navigates away.
>
>
> --
> Alpar Torok
>



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Multithreading in PHP

am 17.03.2009 14:58:58 von Sudheer Satyanarayana

Manoj Singh wrote:
> Hi Guys,
>
> I am creating a page which submits the form through Ajax request & the
> submitted page is sending the mails to n number of users. Now until the mail
> sends or the page process completed the end user has to wait.
>
> Is it possible that server sends the response to the client & then start
> processing so that the client doesn't have to wait for the server response.
>
>
>
I can think of two ways to solve this apart from creating an Ajax request:

1. Queue the emails. Run a cron job to process the queue later.
2. Send the email after you flush the output.


--

With warm regards,
Sudheer. S
Business: http://binaryvibes.co.in, Tech stuff: http://techchorus.net, Personal: http://sudheer.net


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Multithreading in PHP

am 17.03.2009 15:02:06 von Manoj Singh

--00221532cf34201d3204655103ba
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

Hi Sudheer,

Can you please put more focus or sample code for the second option which you
have suggested "Send the email after you flush the output.".

Regards,
Manoj

On Tue, Mar 17, 2009 at 7:28 PM, Sudheer Satyanarayana <
sudheer.s@binaryvibes.co.in> wrote:

> Manoj Singh wrote:
>
>> Hi Guys,
>>
>> I am creating a page which submits the form through Ajax request & the
>> submitted page is sending the mails to n number of users. Now until the
>> mail
>> sends or the page process completed the end user has to wait.
>>
>> Is it possible that server sends the response to the client & then start
>> processing so that the client doesn't have to wait for the server
>> response.
>>
>>
>>
>>
> I can think of two ways to solve this apart from creating an Ajax request:
>
> 1. Queue the emails. Run a cron job to process the queue later.
> 2. Send the email after you flush the output.
>
>
> --
>
> With warm regards,
> Sudheer. S
> Business: http://binaryvibes.co.in, Tech stuff: http://techchorus.net,
> Personal: http://sudheer.net
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--00221532cf34201d3204655103ba--

Re: Multithreading in PHP

am 17.03.2009 15:07:39 von Sudheer Satyanarayana

Manoj Singh wrote:
> Hi Sudheer,
>
> Can you please put more focus or sample code for the second option
> which you have suggested "Send the email after you flush the output.".
>
//Code to send some output to user
....
....
....
echo "Email will be sent to you shortly";
//Time to send email
//Send all other output before this line
ob_flush();
flush();

//Code to send email
//echo "Email sent";

--

With warm regards,
Sudheer. S
Business: http://binaryvibes.co.in, Tech stuff: http://techchorus.net, Personal: http://sudheer.net


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Multithreading in PHP

am 17.03.2009 21:43:03 von Manuel Lemos

Hello,

on 03/17/2009 10:14 AM Manoj Singh said the following:
> I am creating a page which submits the form through Ajax request & the
> submitted page is sending the mails to n number of users. Now until the mail
> sends or the page process completed the end user has to wait.
>
> Is it possible that server sends the response to the client & then start
> processing so that the client doesn't have to wait for the server response.

You will need to use AJAX/COMET requests. Regular XMLHttpRequest AJAX
requests will not do because when you send the AJAX response your script
exits.

With AJAX/COMET requests you can send several responses to the same
request without exiting the script, so you can show progress report.

Take a look at these articles:

http://www.phpclasses.org/blog/post/58-Responsive-AJAX-appli cations-with-COMET.html

http://www.phpclasses.org/blog/post/51-PHPClasses-20-Beta-AJ AX-XMLHttpRequest-x-IFrame.html


This forms class comes with an AJAX/COMET plug-in that allows you to
show progress of a task running on the server without page reloading in
a single request.

http://www.phpclasses.org/formsgeneration

Here is is a live example script that show progress of a task running on
the server after the form is submitted.

http://www.meta-language.net/forms-examples.html?example=tes t_ajax_form


--

Regards,
Manuel Lemos

Find and post PHP jobs
http://www.phpclasses.org/jobs/

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: Re: Multithreading in PHP

am 18.03.2009 10:07:14 von Andrea Giammarchi

--_1f41aab7-16b3-4975-9363-89f0155a7973_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable


If anybody interested=2C this is my "old" comet implementation in PHP:
http://webreflection.blogspot.com/2008/04/phomet-changes-nam e-so-welcome-ph=
ico.html

P.S. Hi Manuel=2C ages I do not read you ( ages I do not post my classes in=
phpclasses.org :-) )

> Date: Tue=2C 17 Mar 2009 17:43:03 -0300
> From: mlemos@acm.org
> To: manojsingh2121@gmail.com
> CC: php-general@lists.php.net
> Subject: [PHP] Re: Multithreading in PHP
>=20
> Hello=2C
>=20
> on 03/17/2009 10:14 AM Manoj Singh said the following:
> > I am creating a page which submits the form through Ajax request & the
> > submitted page is sending the mails to n number of users. Now until the=
mail
> > sends or the page process completed the end user has to wait.
> >=20
> > Is it possible that server sends the response to the client & then star=
t
> > processing so that the client doesn't have to wait for the server respo=
nse.
>=20
> You will need to use AJAX/COMET requests. Regular XMLHttpRequest AJAX
> requests will not do because when you send the AJAX response your script
> exits.
>=20
> With AJAX/COMET requests you can send several responses to the same
> request without exiting the script=2C so you can show progress report.
>=20
> Take a look at these articles:
>=20
> http://www.phpclasses.org/blog/post/58-Responsive-AJAX-appli cations-with-=
COMET.html
>=20
> http://www.phpclasses.org/blog/post/51-PHPClasses-20-Beta-AJ AX-XMLHttpReq=
uest-x-IFrame.html
>=20
>=20
> This forms class comes with an AJAX/COMET plug-in that allows you to
> show progress of a task running on the server without page reloading in
> a single request.
>=20
> http://www.phpclasses.org/formsgeneration
>=20
> Here is is a live example script that show progress of a task running on
> the server after the form is submitted.
>=20
> http://www.meta-language.net/forms-examples.html?example=3Dt est_ajax_form
>=20
>=20
> --=20
>=20
> Regards=2C
> Manuel Lemos
>=20
> Find and post PHP jobs
> http://www.phpclasses.org/jobs/
>=20
> PHP Classes - Free ready to use OOP components written in PHP
> http://www.phpclasses.org/
>=20
> --=20
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe=2C visit: http://www.php.net/unsub.php
>=20

____________________________________________________________ _____
News=2C entertainment and everything you care about at Live.com. Get it now=
!
http://www.live.com/getstarted.aspx=

--_1f41aab7-16b3-4975-9363-89f0155a7973_--

Built-in objects APC or serializationþþ

am 18.03.2009 10:15:53 von Andrea Giammarchi

--_6b70939c-ea2a-4a93-9a26-ed9a5134df35_
Content-Type: text/plain; charset="windows-1256"
Content-Transfer-Encoding: 8bit


I think I had some problem with this ML ... so I try again to write down my question:

I would like to know if there a generic extension/3rd
parts/solution to save the state of a built-in PHP object.

I perfectly know that __sleep and __wakeup or ... implements
Serializable { ... } could allow me to store and retrieve serialized
data but what I did not expect is that APC just behaves as serialize
and "nothing more" than that.

Here there is a quick explanation:



$xsltp = new XSLTProcessor;

$xsltp->importStylesheet(

DomDocument::load('random.xsl')

);



// no way to store the variable here with its live state

// without re-importing stylesheet on __wakeup or unserialize



echo $xsltp->transformToXML(

DomDocument::load('random.xml')

);



I agree that this built-in stuff could be considered a weird case but I
cannot believe that with all these new classes there is no solution to
truly "hibernate" instances state.



As summary, I wonder if any of you knows a solution or, if any, when (and if) are you planning to add this feature.



Best Regards

____________________________________________________________ _____
More than messages–check out the rest of the Windows Live™.
http://www.microsoft.com/windows/windowslive/
--_6b70939c-ea2a-4a93-9a26-ed9a5134df35_--

Re: Multithreading in PHP

am 18.03.2009 11:52:06 von torokalpar

2009/3/17 Manoj Singh :
> Hi Alpar,
>
> Thanks for reply.
>
> Actually the form is submitted through ajax request and the validation is
> checking on the server side. So if any error occurs on submission of form=
,
> then we are displaying the errors to the user. And is there is no error,
> then the submitted page started processing. So here client has to wait un=
til
> the page process completed or not. What i want here if possible, after
> validating the user input server sends the thanks response to the client =
so
> that cleint doesn't has to wait, then the server starts the processing.
> Please suggest if it is possible.
>
> Regards,
> Manoj
>
>
>
> On Tue, Mar 17, 2009 at 7:01 PM, Alpár Török mail.com> wrote:
>>
>> 2009/3/17 Manoj Singh :
>> > Hi Guys,
>> >
>> > I am creating a page which submits the form through Ajax request & the
>> > submitted page is sending the mails to n number of users. Now until th=
e
>> > mail
>> > sends or the page process completed the end user has to wait.
>> >
>> > Is it possible that server sends the response to the client & then sta=
rt
>> > processing so that the client doesn't have to wait for the server
>> > response.
>> >
>> > Please suggest.
>> >
>> > Regards,
>> > Manoj
>> >
>> Since you are using Ajax requests, which by their nature are
>> asynchronous , your user won't have to wait. You can write some JS
>> code to let him know that the request was sent, and just let the ajax
>> call run in the background. On the server side make sure to ignore
>> user abort, just in case the user navigates away.
>>
>>
>> --
>> Alpar Torok
>
>

Let me be more specific. it goes like this:

front end:

submit ajax,
on server response check if the input didn't validate, or if the
task finished, offer fedback

on the server:
ignore user intrerupt with ignore_user_abort(); and adjust max
execution time
validate the input
send back errors if the the input doesn't validate (at this point
the user won't have to wait for a long time)
start the task that takes really long
send a message that the task was done

The user will either be on the page and get the message (if you want
to show one) or navigated away by this time, but your processing is
still done.
--=20
Alpar Torok

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Built-in objects APC or serializationþþ

am 18.03.2009 13:34:58 von Jochem Maas

you shouldn't start a new thread by replying to an existing one.

also, you've already asked this question.

Andrea Giammarchi schreef:
> I think I had some problem with this ML ... so I try again to write down my question:

.... this is not paid support, asking a question garantees neither an answer nor
a solution (actually, thinking about it, that probably not a good definition of
'paid support' either).

>
> I agree that this built-in stuff could be considered a weird case but I
> cannot believe that with all these new classes there is no solution to
> truly "hibernate" instances state.

php doesn't care about what we believe. some research into the concept
of 'shared nothing' may be in order to clarify why you hibernation wish is
not supported out of the box.

as for making an implementation, you've already answered your own question
with __sleep, __wake & Serializable

>
> As summary, I wonder if any of you knows a solution or, if any, when (and if) are you planning to add this feature.
>

although I don't develop the php engine I think I can safely say nobody is
planning this 'feature' (with you current definition I can only describe as
nebulous). if you keep an eye on the current developments in php you'll
realise that the core developers have their hands full already with a delayed
5.3, a stack of features slated for post 5.3 and a 'small' thing called
php6 (native unicode implementation)

>
> Best Regards
>
> ____________________________________________________________ _____
> More than messages–check out the rest of the Windows Live™.
> http://www.microsoft.com/windows/windowslive/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Re: Multithreading in PHP

am 20.03.2009 07:04:06 von Manuel Lemos

Hello Andrea,

on 03/18/2009 06:07 AM Andrea Giammarchi said the following:
> If anybody interested, this is my "old" comet implementation in PHP:
> http://webreflection.blogspot.com/2008/04/phomet-changes-nam e-so-welcome-phico.html

Great! Any live examples page?


> P.S. Hi Manuel, ages I do not read you ( ages I do not post my classes in phpclasses.org :-) )

Oh, yes, feel free to get back. Hopefully soon the PHPClasses site will
share ad revenue with the best contributors! ;-)


--

Regards,
Manuel Lemos

Find and post PHP jobs
http://www.phpclasses.org/jobs/

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Re: Multithreading in PHP

am 23.03.2009 14:05:03 von Igor Escobar

--000325574d8e2664b40465c8ea80
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

Great Project, Lemos.

When you are thinking in show more exemples?

Regards,
Igor Escobar
systems analyst & interface designer
www . igorescobar . com



On Fri, Mar 20, 2009 at 3:04 AM, Manuel Lemos wrote:

>
> Hello Andrea,
>
> on 03/18/2009 06:07 AM Andrea Giammarchi said the following:
> > If anybody interested, this is my "old" comet implementation in PHP:
> >
> http://webreflection.blogspot.com/2008/04/phomet-changes-nam e-so-welcome-phico.html
>
> Great! Any live examples page?
>
>
> > P.S. Hi Manuel, ages I do not read you ( ages I do not post my classes in
> phpclasses.org :-) )
>
> Oh, yes, feel free to get back. Hopefully soon the PHPClasses site will
> share ad revenue with the best contributors! ;-)
>
>
> --
>
> Regards,
> Manuel Lemos
>
> Find and post PHP jobs
> http://www.phpclasses.org/jobs/
>
> PHP Classes - Free ready to use OOP components written in PHP
> http://www.phpclasses.org/
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--000325574d8e2664b40465c8ea80--

Re: Re: Multithreading in PHP

am 23.03.2009 18:31:03 von Manuel Lemos

Hello,

on 03/23/2009 10:05 AM Igor Escobar said the following:
> Great Project, Lemos.

Thanks?

> When you are thinking in show more exemples?

Who? Me or Andrea?

--

Regards,
Manuel Lemos

Find and post PHP jobs
http://www.phpclasses.org/jobs/

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php