Am urmatorul script:
<?php
echo 'text 1';
echo 'text 2';
?>
As vrea ca sa pot intarzia text 2 astfel incat sa apara la un anumit interval de timp fata de text 1 de exemplu la 3 secunde. Am incercat sa folosesc functia sleep () inserand-o intre cele 2 echo dar imi intarzie executarea intregului script. Va multumesc anticipat daca ma puteti ajuta!
Cum pot sa fac un delay in PHP...
Moderatori: Moderatori, Start Moderator
-
daniel_bondoc
- PHPRomania Supporter
- Mesaje: 16
- Membru din: Mie Oct 12, 2005 6:38 pm
PHP: sleep - Manual :: User notes scrie:it is a bad idea to use sleep() for delayed output effects as
1) you have to flush() output before you sleep
2) depending on your setup flush() will not work all the way to the browser as the web server might apply buffering of its own or the browser might not render output it thinks not to be complete
netscape for example will only display complete lines and will not show table parts until the </table> tag arrived
so use sleep if you have to wait for events and don't want to burn to much cycles, but don't use it for silly delayed output effects!
-
daniel_bondoc
- PHPRomania Supporter
- Mesaje: 16
- Membru din: Mie Oct 12, 2005 6:38 pm
-
johnutz
- Senior Member
- Mesaje: 956
- Membru din: Mar Iul 20, 2004 9:23 am
- Localitate: Între scaun şi tastatură
mai e ceva:
Mai demult am facut cam asa: [php]<?php
echo 'text1';
echo '<!-- ' . str_repeat(' ', 256) . '-->';
sleep(3); // de fapt, in loc de sleep apelam un executabil cu system(), deci se muncea, nu se dormea
echo 'text2';
echo '<!-- ' . str_repeat(' ', 256) . '-->';
?>[/php]
http://ro.php.net/manual/en/function.flush.php scrie: Even the browser may buffer its input before displaying it. Netscape, for example, buffers text until it receives an end-of-line or the beginning of a tag, and it won't render tables until the </table> tag of the outermost table is seen.
Some versions of Microsoft Internet Explorer will only start to display the page after they have received 256 bytes of output, so you may need to send extra whitespace before flushing to get those browsers to display the page.
Mai demult am facut cam asa: [php]<?php
echo 'text1';
echo '<!-- ' . str_repeat(' ', 256) . '-->';
sleep(3); // de fapt, in loc de sleep apelam un executabil cu system(), deci se muncea, nu se dormea
echo 'text2';
echo '<!-- ' . str_repeat(' ', 256) . '-->';
?>[/php]
asta e de cand eram tanar 
Sar putea sa nu fie exact ceea ce cauti, dar javascript te-ar ajuta mult mai mult.
Daca combini window.setInterval() si window.setTimeout() cu document.write() efectul vazut de vizitator va fi acela de text scris cu intarziere, cu toate ca pagina a fost trimisa toata odata fara sleep.
Daca combini window.setInterval() si window.setTimeout() cu document.write() efectul vazut de vizitator va fi acela de text scris cu intarziere, cu toate ca pagina a fost trimisa toata odata fara sleep.
-
daniel_bondoc
- PHPRomania Supporter
- Mesaje: 16
- Membru din: Mie Oct 12, 2005 6:38 pm
Cine este conectat
Utilizatori ce ce navighează pe acest forum: Niciun utilizator înregistrat și 35 vizitatori

