473,326 Members | 2,173 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,326 software developers and data experts.

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 help much

thx
Jun 27 '08 #1
5 1267
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 help 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.
js*******@attglobal.net
==================

Jun 27 '08 #2
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 help.

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

Jun 27 '08 #3
On Jun 22, 8:59*am, Iván Sánchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.orgwrote:
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 help.

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
Jun 27 '08 #4
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.
Jun 27 '08 #5
On Sun, 22 Jun 2008 09:52:45 -0700 (PDT), lazy wrote:
On Jun 22, 8:59*am, Iván Sánchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.orgwrote:
>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 help.


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
Jun 27 '08 #6

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

Similar topics

6
by: lenny | last post by:
Hi, I've been trying to use a Sub or Function in VBA to connect to a database, make a query and return the recordset that results from the query. The connection to the database and the query...
12
by: harishg2 | last post by:
Hi, How to store a variable value for more than one executions. Ex: main() { int i=0; i++; printf("%d",i);
9
by: Gomaw Beoyr | last post by:
Two question about the "partial classes" (in the next wersion of ..NET). Question 1 ========== Will partial classes (in the next version of C#) have to be declared "partial" in ALL places. ...
0
by: K Altsj? | last post by:
If passing a DataSet to a web method for update using ADO.NET and the update fails, the parameter list may get corrupt. The following code example consists of a Web Service and a consumer console...
0
by: Mrozik | last post by:
after parsing WSDL definition of java WebService, C# proxy class contains data strutures (I'm using RPC\encoded): public class DateString { /// <remarks/> public string value; }
0
by: r1 | last post by:
I am relatively inexperienced in using delegates and asynchronous methods. I read several articles, and then I developed my own code with a mission to improve the performance. Wow! I cannot...
5
by: Matthew Wilson | last post by:
I wrote some code to create a user and update a user on a remote box by sending emails to that remote box. When I was done, I realized that my create_user function and my update_user function were...
13
by: Thomas Neubauer | last post by:
Hello, i am learning c# and have created now a simple project that just creates 6 random numbers. My form includes a button and 6 labels for the random numbers. The program seems to work...
10
by: JDeats | last post by:
So I have a class that spans over two partial classes in code, here's an example (do not read much into this, the code is of no practical use, this is just a simple example of where my confusion...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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.