473,387 Members | 1,899 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,387 software developers and data experts.

How to send data a little at a time?

I have a script that makes multiple requests to several sites. However,
each request takes a little while. How can I get the PHP script to
output data to let the user know that it's checking? For example, I have

echo "Checking...";

at the beginning, before I do any hocus-pocus, but it doesn't show up
until the script is done. How do I get it to send some data at a time?
Oct 18 '05 #1
3 1509
> I have a script that makes multiple requests to several sites. However,
each request takes a little while. How can I get the PHP script to
output data to let the user know that it's checking? For example, I have

echo "Checking...";

at the beginning, before I do any hocus-pocus, but it doesn't show up
until the script is done. How do I get it to send some data at a time?


This can be a little difficult. For certain browsers they will not
display anything until there is a certain byte size reached. However
there are a few ways... I will take you through a few of them.

1) Create an image that tells them it is processing when they click it,
show it when the user clicks submit and then hide it on completion.

2) The AJAX way
If you want to make an AJAX request it is far easier than flushing the
output. For instance if you use AjaxRequest (www.ajaxtoolbox.com), you
could use the onLoading to display the contents as they are flushed to
the browser, then onSuccess when it is finished. See the examples for
details on how to implement this.
3) The harder way (requires some research)
You can use flush from php, but this doesn't always work correctly. See
the manual for an explaination (http://www.php.net/flush)

I would suggest using AJAX as you can take that content and replace it
into the current area after you have processed it.

--
Mike Willbanks
Zend Certified Engineer
http://www.digitalstruct.com
Oct 18 '05 #2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Mike Willbanks wrote:
I have a script that makes multiple requests to several sites.[...]
How do I get it to send some data at a time?
[...] 1) Create an image that tells them [...]
2) The AJAX way[...]
3) The harder way (requires some research)


4) The threaded way

Use pcntl_fork() to create a child process (or, if posible, a thread) for
each site request. As all the children share the same stdout file
descriptor, you should be able to echo() text to the browser asyncronously
(or, you could use popen() or some other pipe mechanism to centrlize the
output).
However, this approach has the disadvantage of potentially becoming a
concurrency hell. Make sure you have the proper inter-locking mechanisms to
access the shared resources (in this case, stdout).

- --
- ----------------------------------
Iván Sánchez Ortega -i-punto-sanchez--arroba-mirame-punto-net

Un ordenador no es un televisor ni un microondas, es una herramienta
compleja.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFDVKvN3jcQ2mg3Pc8RAsloAJ0Rpdq0Z9erPIYXC1W/1dDxrg6ioACfed+x
qXepWc2RlJu2XXfO1Gx16Dw=
=Ts+N
-----END PGP SIGNATURE-----
Oct 18 '05 #3

Iván Sánchez Ortega wrote:
4) The threaded way

Use pcntl_fork() to create a child process (or, if posible, a thread) for
each site request. As all the children share the same stdout file
descriptor, you should be able to echo() text to the browser asyncronously
(or, you could use popen() or some other pipe mechanism to centrlize the
output).


Probably easier to just poll a bunch of non-blocking streams.

Oct 18 '05 #4

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

Similar topics

6
by: Quarco | last post by:
Hi, Quick & simple question: I have to send the next data to a socket in order to make a popup visible on a windows machine.. TITLE Title of popup TEXT Text in popup POPUP
4
by: jas | last post by:
I have a basic client/server socket situation setup....where the server accepts a connection and then waits for commands. On the client side, I create a socket, connect to the server...then I...
2
by: Fatih BOY | last post by:
Hi, I want to send a report from a windows application to a web page like 'report.asp' Currently i can send it via post method with a context like local=En&Username=fatih&UserId=45&Firm=none...
0
by: zhimin | last post by:
Hi, I'm writing a program to send large file(100m) through dotnet using TCPListener & TCPClient, I'm sending the file with a ask and response loop: 1. Client send a flag 1 to server indicate it...
6
by: John J. Hughes II | last post by:
I have a service that needs to send e-mail alerts. I have been attempting to use the System.Net.Mail function from .NET but this seems to require the IIS be installed and running. Since some of...
2
by: Pablo | last post by:
Hi at all! How can i send a DATA (not a DataTime) Type to a Java WebService? In .NET we have only a DataTime that is incompatible with the Data (calendar) Type of Java! How can i resolve this...
0
southoz
by: southoz | last post by:
Good ay all , I'm fairly new to access(a little over 5 weeks now). Since I'v started I have picked up a lot of useful information from forums such as this and in doing so will share that information...
14
by: eliss.carmine | last post by:
I'm using TCP/IP to send a Bitmap object over Sockets. This is my first time using C# at all so I don't know if this is the "right" way to do it. I've already found out several times the way I was...
1
by: danfolkes | last post by:
Hey Everyone, I am trying to send repeated messages from a "Node" to a "Server". It works the first time I send the from the Node to Server, but after that it either errors, or does not do...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.