Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP] Odbieranie danych przez przeglądarkę w trakcie wykonywania
Forum PHP.pl > Forum > Przedszkole
patryk9200
Cześć,
Mam problem jak zrobić żeby skrypt który wykonuje się ~30 min przekazywał do przeglądarki dane o postępie prac?
mam w nim skrypt który powinien dotrzeć do przeglądarki w trakcie wykonywania, oraz jeden na samym początku.
Wygląda to tak:
  1.  
  2.  
  3.  
  4. <?php //WYSYŁANE PRZED WYKONANIEM ->
  5. ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  6. <html>
  7. <head>
  8. <title>Kontrola</title>
  9. <meta http-equiv="content-type" content="text/html; charset=utf-8">
  10. <script type='text/javascript'>
  11. skrypt
  12. </script>
  13. </head><body OnLoad="timerStart();">
  14. <h2>Czas działania:<b id='time_counter'></b></h2>
  15. <table border="1" width="400px" height="30"><tr><td id="postep" width="2px" bgcolor="green">
  16. </td><td></td></tr></table>
  17. <?
  18. function Clen($document){
  19. $search = array('@<script[^>]*?'.'>.*?</script>@si', // Strip out javascript
  20. '@<head[^>]*?'.'>.*?</head>@si', //<head>
  21. '@<div class="navigation">.*?<ol>.*?</ol>.*?</div>@si', //menu
  22. '@<div class="tab1 page">.*?<div class="row headline">@si',
  23. '@<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">.*?<div class="margin" style="width:430px;">@si',
  24. '@<!-- .box-content -->.*?</html>@si',
  25. '@<!-- tabOverview.ftl -->.*?</div><!-- .col -->@si',
  26. '@<div class="feature-pairs">.*?@si',
  27. '@<body class="des pl des_pl ">.*?<!-- d-59-destext -->@si',
  28. '@<div id="contactFormDiv1">.*?<!-- /bottomContactForm -->@si',
  29. // '@<style[^>]*?'.'>.*?</style>@siU', // Strip style tags properly
  30. // '@<[/!]*?[^<>]*?'.'>@si', // Strip out HTML tags
  31. '@<![sS]*?--[ tnr]*>@', // Strip multi-line comments including CDATA
  32. '@\n@si',
  33. '@<div class="infoBoxContent ">.*?</div>@si',
  34. '@<a title="Informacje"^.*?@si',
  35. );
  36. $data = preg_replace($search, '', $document);
  37.  
  38.  
  39. $data= str_replace("&nbsp;","",$data);
  40. $data = ereg_replace ("(\t)+", "\t", $data);
  41. $data = ereg_replace ("\r\n", "", $data);
  42. return ereg_replace (" +", " ", $data);
  43.  
  44. return $datat;
  45. }
  46.  
  47.  
  48. $server = "#";
  49. $user = "#";
  50. $pwd = "#";
  51.  
  52. $link = mysql_connect($server, $user, $pwd);
  53. if (!$link) {
  54. die('Could not connect: ' . mysql_error());
  55. }
  56. $db_selected = mysql_select_db('c3', $link);
  57. if (!$db_selected) {
  58. die ('Can\'t use $dbName : ' . mysql_error());
  59. }
  60. $result = mysql_query('SELECT * FROM #'); mysql_close();
  61. $i = 0;
  62. while ($row = mysql_fetch_assoc($result)) {
  63. $i++;
  64. $url = NULL;
  65. $cena = NULL;
  66. $strona3 = NULL;
  67. $urls = NULL;
  68. $cena = $row['a2'];
  69. $url = $row['add'];
  70. $url=str_replace('quick', 'short', $url);
  71.  
  72. include ('downpage.php');
  73. if (!empty($url)) {
  74. $urls= ''.$row['link'].'';
  75. if ($fo = @fopen($urls,'r')) {
  76. if ($strona3 != $cena)
  77. { $d = 2; } else {$d = 1;}
  78. } elseif ($pt == TRUE) {$d = 3;}
  79. else {$d = 4;}
  80. } else { $d = 0;}
  81. $pasek = 400 / $i * 100;
  82. /*#####wysyłane w trakcie informując o postępie prac#########*/
  83. echo $d.'<div onLoad="postep.setAttribute("width","'.$pasek.'");" style="display:none;"></div>';
  84. /*##########################################################*/
  85. $server = "#";
  86. $user = "#";
  87. $pwd = "#";
  88.  
  89. $link = mysql_connect($server, $user, $pwd);
  90. if (!$link) {
  91. die('Could not connect: ' . mysql_error());
  92. }
  93. $db_selected = mysql_select_db('c3', $link);
  94. if (!$db_selected) {
  95. die ('Can\'t use $dbName : ' . mysql_error());
  96. }
  97. $query = mysql_query("UPDATE # SET status='".$d."' WHERE id='".$row['id']."'");mysql_close();
  98. }
  99. ?>
  100. <body OnLoad="timerStop();"></html>


erix
flush?
patryk9200
trochę poszperałem i znalazłem trochę przykładów.
Zrobiłem na nowo, ale i tak nic do przeglądarki nie przekazuje.
Kod:
  1. <html>
  2. <head>
  3. <script language="JavaScript">
  4. <!--
  5. var loaded=0;
  6. setTimeout("info()",5000);
  7. function info() {
  8. txt=document.body.innerHTML;
  9. ar=txt.split("_prg_:");
  10. prg=ar[ar.length-1];
  11. if (ar.length>1) document.getElementById('progress').innerHTML="Liczba wykonanych zapytan: "+ prg;
  12. setTimeout("info()",5000);
  13. }
  14. //-->
  15. </script>
  16. </head>
  17. <body>
  18. <div id="progress">&nbsp; </div>
  19. <table style="border: 2px; width: 500px; height: 20px">
  20. <tr>
  21. <td>
  22. <table><tr><td id="postep" border="2px" width="1%" height="18px" bgcolor="green"></td></tr></table>
  23. </td>
  24. </tr>
  25. </table>
  26. <div id="ukryj">
  27. <?php
  28. flush();
  29. function Clen($document){
  30. $search = array('@<script[^>]*?'.'>.*?</script>@si', // Strip out javascript
  31. '@<head[^>]*?'.'>.*?</head>@si', //<head>
  32. '@<div class="navigation">.*?<ol>.*?</ol>.*?</div>@si', //menu
  33. '@<div class="tab1 page">.*?<div class="row headline">@si',
  34. '@<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">.*?<div class="margin" style="width:430px;">@si',
  35. '@<!-- .box-content -->.*?</html>@si',
  36. '@<!-- tabOverview.ftl -->.*?</div><!-- .col -->@si',
  37. '@<div class="feature-pairs">.*?@si',
  38. '@<body class="des pl des_pl ">.*?<!-- d-59-destext -->@si',
  39. '@<div id="contactFormDiv1">.*?<!-- /bottomContactForm -->@si',
  40. // '@<style[^>]*?'.'>.*?</style>@siU', // Strip style tags properly
  41. // '@<[/!]*?[^<>]*?'.'>@si', // Strip out HTML tags
  42. '@<![sS]*?--[ tnr]*>@', // Strip multi-line comments including CDATA
  43. '@\n@si',
  44. '@<div class="infoBoxContent ">.*?</div>@si',
  45. '@<a title="Informacje"^.*?@si',
  46. );
  47. $data = preg_replace($search, '', $document);
  48.  
  49.  
  50. $data= str_replace("&nbsp;","",$data);
  51. $data = ereg_replace ("(\t)+", "\t", $data);
  52. $data = ereg_replace ("\r\n", "", $data);
  53. return ereg_replace (" +", " ", $data);
  54.  
  55. return $datat;
  56. }
  57.  
  58.  
  59.  
  60.  
  61. $link = mysql_connect($server, $user, $pwd);
  62. if (!$link) {
  63. die('Could not connect: ' . mysql_error());
  64. }
  65. $db_selected = mysql_select_db('c3autos', $link);
  66. if (!$db_selected) {
  67. die ('Can\'t use $dbName : ' . mysql_error());
  68. }
  69. $result = mysql_query('SELECT * FROM a'); mysql_close();
  70. $i = 0;
  71. $ilosc_wierszy = mysql_num_rows($result);
  72. while ($row = mysql_fetch_assoc($result)) {
  73. $i++;
  74. $url = NULL;
  75. $cena = NULL;
  76. $strona3 = NULL;
  77. $urls = NULL;
  78. $cena = $row['a2'];
  79. $url = $row['add'];
  80. include ('downpage.php');
  81. if (!empty($url)) {
  82. $urls= ''.$row['link'].'';
  83. if ($fo = @fopen($urls,'r')) {
  84. if ($strona3 != $cena)
  85. { $d = 2; } else {$d = 1;}
  86. } elseif ($pt == TRUE) {$d = 3;}
  87. else {$d = 4;}
  88. } else { $d = 0;}
  89. $pasek = round( $i/$ilosc_wierszy * 100);
  90. echo '\n_prg_:'.$i;
  91. echo '<script language="JavaScript">
  92. <!-- document.getElementById(\'postep\')..setAttribute(\'width\',\''.$pasek.'%\'); //-->
  93. </script>';
  94. flush();
  95.  
  96.  
  97. $link = mysql_connect($server, $user, $pwd);
  98. if (!$link) {
  99. die('Could not connect: ' . mysql_error());
  100. }
  101. $db_selected = mysql_select_db('c3autos', $link);
  102. if (!$db_selected) {
  103. die ('Can\'t use $dbName : ' . mysql_error());
  104. }
  105. $query = mysql_query("UPDATE a SET status='".$d."' WHERE id='".$row['id']."'");mysql_close();
  106. }
  107. for ($i=0;$i<100;$i++) {
  108. echo "\n_prg_:".$i;
  109. flush();
  110. sleep(1);
  111. }
  112. ?>
  113. </div>
  114. </body>
  115. </html>


skrypt który wykożystałem jest z tej strony: http://forum.php.pl/index.php?showtopic=92...rt=#entry463282

ale on sam bez zmian też nie działa







Czy może to być spowodowane tym, że skrypty uruchamiam w trybie CGI ? czy nie ma to znaczenia?





Rysh
patryk9200, już zaczynasz denerwować. Codziennie usuwasz i wklejasz ponownie ostatni post żeby cały czas być wyżej w temacie. Jeśli ktoś by potrafił to by Ci pomógł. Do tego czasu sam już byś sobie poradził z rozwiązaniem swojego problemu.


//Przepraszam za spam.
erix
Nie, masz rację; też mi się wydawało, że bez przerwy podbija ten temat.

Zamykam, koniec tego dobrego.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.