A continuación, os voy a mostrar un código muy tonto pero extremadamente útil.
Cuando necesitéis lanzar un proceso en php de cierta duración, y queráis conocer el avance del mismo, podéis hacer una barra de progreso fácilmente con las siguientes líneas de código.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
<? header( 'Content-type: text/html; charset=utf-8' ); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Documento sin título</title> <style> .progreso { width: 100px; height: 20px; border:1px solid black; float:left;} .avance { height:20px; float:left; background: red; } </style> </head> <body> <div class="progreso"> <div class="barra"> <? for($i=0;$i<10;$i++) { echo '<span style="width:10px;" class="avance"></span>'; flush(); ob_flush(); sleep(5); } ?> </div> </div> </body> </html> |
Evidentemente, el ancho del progreso (en px) habrá que calcularlo de forma dinámica según el número de instrucciones o ciclos de vuestro script, pero en esencia, con esas líneas tan estúpidas todo os será un poquito más fácil.
Además, con ello evitáis el timeout del navegador. Si el proceso es extremadamente largo, podéis poner otro par de líneas salvadoras en la cabecera del script y éste se ejecutará…sí o sí.
1 2 3 4 |
// si el usuario cierra el navegador, el script sigue ejecutándose ignore_user_abort(true); // cancela el límite de tiempo de ejecución de php set_time_limit(0); |
Ya os veo a todos pensando en hacer una fantástica newsletter…. Eso, próximamente.
Barra de progreso PHP,
8 comentarios
home page
home page en dijo:It’s in fact very difficult in this busy life to listen news on Television, so I
only use web for that purpose, and obtain the latest information.
weightlifting shoes
weightlifting shoes en dijo:Jordan original shoes base price is 25000 and this Jordan shoes in this Blog
being sold for 3000 this is copy of original.
Those are a scam id rather tie them mysleves.
Look into my web site; weightlifting shoes
How Dog Feces Is Bad?
How Dog Feces Is Bad? en dijo:I do not even understand how I ended up here, however I thought this post was
good. I do not realize who you are but certainly you’re going to a well-known blogger when you aren’t
already. Cheers!
lap band procedure
lap band procedure en dijo:Instant entertainment in the flick of a switch; instant
exposire to your maates vvia Facebook or text; instant requirement forr medical fixes rather tthan waiting to find out
if youur body can heal itself of a cold, or virus, without the need for a
visit to the doctor; own it now with credit cards, as opposed to save up and purchase
it if the momey is available. It also increases cell sensitivity to insulin,
shown to help get ridd of fat by raising our muscle metabolism rate.
I decided to write this because many a time have people inquired about is there a worst food
you can eat.
smart contract
smart contract en dijo:Fantastic website. A lot of helpful info here.
I am sending it to some buddies ans additionally sharing in delicious.
And certainly, thanks for your effort!
ichungcumoi.info
ichungcumoi.info en dijo:The fact is, this can be a well-known investment vehicle
specifically for the center and upper class. Cabral was very impressed by the beauty of the place and thus will anyone
today. The first property that I bought back
1998 for $69,000 (that I still own today) may be worth $170,000 today.
l
l en dijo:esto ees lo
l
l en dijo:l