Help - Search - Members - Calendar
Full Version: Is It Possible To Create A Loading Using Php
Zymic Webmaster Forums > Web Design & Development > Server Side Scripting > PHP
G_ze_09
unsure.gif Hi guys would it be possible to create a loading bar while sending a message?
EMOruffino
QUOTE(G_ze_09 @ Oct 20 2007, 02:53 AM) *
unsure.gif Hi guys would it be possible to create a loading bar while sending a message?


this can be done very easily with Ajax within in PHP.... exactly what type of message are we sending...
is it a contact form? a PM or even IM?

Are you using a CMS or forum software or is it custom?

please be more specific!

G_ze_09
A PM and It is custom, by the way i know basic ajax but would it be hard for me to learn such advance script for it (the loading staff) .

by the way, Thanks for the reply. wink.gif
G_ze_09
Thank you very much, this site is a really big help for me!

Thanks again sir.
Ed
Well it's best to think about the properties you need to relate the progress,

All you need to have is a current position and an end position, the calculation for percentage would simply be:

CODE
(currentPosition / endPosition) * 100


Then you would round that off, the problem is however retrieving these values, the end position you could retrieve from the 'Content-Length' header yet the current you would have to log the current position in the raw data.

Then in javascript you could calculate the percentage, then set the width property on an element to reflect that.

If it's not a multipart form you can just use:

php://input

That will retrieve the raw data, multipart is a whole different ball park. The other option is to just have a simple bar that whizzes backwards and forwards and on completion sets some file (which is polled) to a new value and then that signifies that the message has been sent.
Zytran
Since it's a custom cms, why not make it simple.

Php sleep() function.
http://us3.php.net/manual/en/function.sleep.php

Something like one of these -> http://swik.net/Ajax/Ajax+Images

Show image then sleep(3) for 3 seconds
<img border="0" src="IMAGE_SOURCE">
sleep
then redirect
Ed
QUOTE(Zytran @ Oct 22 2007, 07:28 PM) *
Since it's a custom cms, why not make it simple.

Php sleep() function.
http://us3.php.net/manual/en/function.sleep.php

Something like one of these -> http://swik.net/Ajax/Ajax+Images

Show image then sleep(3) for 3 seconds
<img border="0" src="IMAGE_SOURCE">
sleep
then redirect


How exactly does that constitute a loading bar...

When you sleep you stop script execution, so you effectively increase the loading time of sending the message by 3 seconds, so please explain how that relates the time taken to send the message? You could just output an image at the end of sending the message without the sleep and achieve exactly the same result which again does not relate the sending time.
Zytran
QUOTE(Bread @ Oct 22 2007, 06:54 PM) *
How exactly does that constitute a loading bar...

When you sleep you stop script execution, so you effectively increase the loading time of sending the message by 3 seconds, so please explain how that relates the time taken to send the message? You could just output an image at the end of sending the message without the sleep and achieve exactly the same result which again does not relate the sending time.

You send the PM, then sleep, nothing special but it does the job of showing process, I think thats all he is looking for.

How could you determine the time it would take to send a "PM" before it was sent?
No bull, Example please.
blink.gif
MrTouz
i think the sleep(3) will sleep and stop the script depending where it has been set no ?

if its set after the sending pm or email than like zytran said itll send the PM and than show a progress bar for 3 sec than go back to what ever page you made.

But is he not looking for a script wich shows a progress bar WHILE sending the PM if its the script, than the sleep(3) cant be set with the sending script since it will stop it for 3 sec than show the progress bar, than restart the script than send and show what ever page is next.

i try to understand this.. but its hard tongue.gif
Zytran
Yes the sleep will halt the script then continue from were the sleep is.
For a simple solution this works fine, If the sleep is in another file, such as sent.php?

Send.php, would be your mail form
Sent.php, would sleep then show message.

I don't see how you can calculate how long it would take to send a message before the message is sent.
---
I'm still waiting on Breads example also.
I think he is just calculating the time is takes to load the form data?
---

MrTouz
can't you use a calculation "function" on some site you have a page made in .... seconds... wouldnt that work to know how much time it took to calculate the mail to be sent ?

doest it really matters if its like 5 seconds or if its 2 seconds ? also does your internet speed matters ? because the submit is sent from your PC to the "server" than the info comes back :/
Ed
First a word of warning; slow connections don't click the following link, it loads a nearly 1mb file into a textarea to demonstrate the load bar.

Here we go:
http://bread.zymic.com/message_sender/

What it does is submits to a hidden iframe. What 'send.php' does is reads php://input and moves through the stream reading x bytes of data with fread, the content-length is retrieved with http://www.php.net/apache_request_headers and the current stream position http://www.php.net/ftell is used for the currentBytes, both total and current bytes are written to an info file as json encoded values.

To relate the progress back to javascript a XMLHttpRequest is sent periodically to poll.php, poll.php reads this written info file containing the json encoded total and current and then calculates a percentage and relates this via the width property of the 'loadbar' div..

The HTML does suffer a little bit from divitus, but width's don't relate through spans and I wasn't too fussed to find an alternative as it's a proof of concept. Feel free to suggest improvements on that score though.

Also, design is very basic... because I am in no way a designer.

I'm not going to release the source, I've pretty much said how it's done smile.gif
G_ze_09
Thank you very much guys for the help and information i really appreciate it. rolleyes.gif
(seems like every member here treated so special. thanks again. rolleyes.gif )

one more thing, how can i determine the size of the data being sent. wacko.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2012 Invision Power Services, Inc.