PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.php > returning partial executions to the user
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
returning partial executions to the user

Réponse
 
LinkBack Outils de la discussion
Vieux 22/06/2008, 16h02   #1
lazy
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut returning partial executions to the user

Hi,
I want to write a script such that it executes 2 mysql queries on the
server. But before executing the second query, I would like to return
the results of the first query to the user and then do my second query
or second query can go on asynchronously

Something like

<?php
$q1=...
mysql_query($q1)
//return the result to user before rest of the script executes

$q2 = ..

?>

Is it possible anyway to flush the output of 1st query to the user
before doing the 2nd query. Can it be done without threading?

ps: Are there any good docs on php threading. Googling didnt much

thx
  Réponse avec citation
Vieux 22/06/2008, 16h06   #2
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: returning partial executions to the user

lazy wrote:
> Hi,
> I want to write a script such that it executes 2 mysql queries on the
> server. But before executing the second query, I would like to return
> the results of the first query to the user and then do my second query
> or second query can go on asynchronously
>
> Something like
>
> <?php
> $q1=...
> mysql_query($q1)
> //return the result to user before rest of the script executes
>
> $q2 = ..
>
> ?>
>
> Is it possible anyway to flush the output of 1st query to the user
> before doing the 2nd query. Can it be done without threading?
>
> ps: Are there any good docs on php threading. Googling didnt much
>
> thx
>


You can't reliably write output to the browser. You can flush the PHP
buffer, but the web server also has a buffer - and it won't send data
until its buffer is filled. Also, the browser won't necessarily show
incomplete data - again, depending on the browser.

You don't find much on PHP threading because you don't typically do
multithreading in PHP. Most PHP scripts (especially web based) are
meant to be short and sweet - get in, do the job and get out.

If you really require such a function, you may have to look at other
languages - a java applet can easily do what you want, for instance.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

  Réponse avec citation
Vieux 22/06/2008, 16h59   #3
Iván Sánchez Ortega
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: returning partial executions to the user

Jerry Stuckle wrote:

> lazy wrote:
>> I want to write a script such that it executes 2 mysql queries on the
>> server. But before executing the second query, I would like to return
>> the results of the first query to the user and then do my second query
>> or second query can go on asynchronously


If you totally *need* to do so, do it client-side. Make the browser request
the first set of data, and when loaded, make it request the second.
Javascript and some AJAX techniques will .


> You don't find much on PHP threading because you don't typically do
> multithreading in PHP. Most PHP scripts (especially web based) are
> meant to be short and sweet - get in, do the job and get out.


Also, multithreading in web servers' processes doesn't usually go very
well - output race conditions and messing with the webserver's threading
model are a recipe for disaster. I speak from experience here. Please don't
try to do threading using the PHP apache module if you don't want to get a
headache.

OTOH, threading goes well with local scripting (when the PHP script is not
tied to a webserver). In this case, the PHP POSIX API works like any other
language - learn to do multithreading in C, you already know how to do
multithreading in PHP.


Cheers,
--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

Proudly running Debian Linux with 2.6.24-1-amd64 kernel, KDE 3.5.9, and PHP
5.2.6-1 generating this signature.
Uptime: 17:53:17 up 14 days, 1:41, 4 users, load average: 0.41, 0.62,
0.58

  Réponse avec citation
Vieux 22/06/2008, 17h52   #4
lazy
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: returning partial executions to the user

On Jun 22, 8:59am, Iván Sánchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.org> wrote:
> Jerry Stuckle wrote:
> > lazy wrote:
> >> I want to write a script such that it executes 2 mysql queries on the
> >> server. But before executing the second query, I would like to return
> >> the results of the first query to the user and then do my second query
> >> or second query can go on asynchronously

>
> If you totally *need* to do so, do it client-side. Make the browser request
> the first set of data, and when loaded, make it request the second.
> Javascript and some AJAX techniques will .



Yeah, I thought of that, but the input data is same for both the
queries and it would be inefficient
request to send the same data again. The first query is the one the
user is waiting for and second query is more for internal
bookkeeping(which the user is not waiting for) but expensive query.



> > You don't find much on PHP threading because you don't typically do
> > multithreading in PHP. Most PHP scripts (especially web based) are
> > meant to be short and sweet - get in, do the job and get out.

>
> Also, multithreading in web servers' processes doesn't usually go very
> well - output race conditions and messing with the webserver's threading
> model are a recipe for disaster. I speak from experience here. Please don't
> try to do threading using the PHP apache module if you don't want to get a
> headache.
>
> OTOH, threading goes well with local scripting (when the PHP script is not
> tied to a webserver). In this case, the PHP POSIX API works like any other
> language - learn to do multithreading in C, you already know how to do
> multithreading in PHP.
>
> Cheers,
> --
> ----------------------------------
> Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-
>
> Proudly running Debian Linux with 2.6.24-1-amd64 kernel, KDE 3.5.9, and PHP
> 5.2.6-1 generating this signature.
> Uptime: 17:53:17 up 14 days, 1:41, 4 users, load average: 0.41, 0.62,
> 0.58


  Réponse avec citation
Vieux 22/06/2008, 18h05   #5
Iván Sánchez Ortega
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: returning partial executions to the user

lazy wrote:

> Yeah, I thought of that, but the input data is same for both the
> queries and it would be inefficient request to send the same data again.


You're doing prepature optimization. Don't. The amount of data needed for
the second query will likely be negligible.

--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

503 Sig Not Found The Signature could not be accessed. Please try again
later.
  Réponse avec citation
Vieux 22/06/2008, 19h47   #6
Peter H. Coffin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: returning partial executions to the user

On Sun, 22 Jun 2008 09:52:45 -0700 (PDT), lazy wrote:
> On Jun 22, 8:59am, Iván Sánchez Ortega <ivansanchez-...@rroba-
> escomposlinux.-.punto.-.org> wrote:
>> Jerry Stuckle wrote:
>> > lazy wrote:
>> >> I want to write a script such that it executes 2 mysql queries on the
>> >> server. But before executing the second query, I would like to return
>> >> the results of the first query to the user and then do my second query
>> >> or second query can go on asynchronously

>>
>> If you totally *need* to do so, do it client-side. Make the browser request
>> the first set of data, and when loaded, make it request the second.
>> Javascript and some AJAX techniques will .

>
>
> Yeah, I thought of that, but the input data is same for both the
> queries and it would be inefficient
> request to send the same data again. The first query is the one the
> user is waiting for and second query is more for internal
> bookkeeping(which the user is not waiting for) but expensive query.


If it's REALLY an expensive query (that is, you've timed it, and it
takes irritatingly long, not just that you THINK it might be expensive
once you write it), spawn that query off to it's own process and have it
write the output to another table that you can read later. See the pcntl
functions at http://us3.php.net/manual/en/ref.pcntl.php for information
about how to do this.

--
"This place is evil! We need weapons! Crossbows! Rocket Launchers!
Rent-a-zilla!"
-- L33t Master Largo www.megatokyo.com
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 02h18.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,13427 seconds with 14 queries