Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> PHP thread
sasiadstar
post
Post #1





Grupa: Zarejestrowani
Postów: 102
Pomógł: 0
Dołączył: 19.06.2015

Ostrzeżenie: (0%)
-----


Witam
Mam taki kod testowy
  1. <?php
  2. ini_set('display_errors', 0);
  3. class CheckIpThread extends Thread {
  4. private $ip;
  5. public $data = null;
  6.  
  7. public function __construct ($ip_to_check) {
  8. $this->ip = $ip_to_check;
  9. }
  10.  
  11. public function run () {
  12. $this->data = th($this->ip);
  13. }
  14. }
  15. $threads = [];
  16.  
  17. for($a=0;$a<=1000;$a=$a+100)
  18. {licz($a);}
  19. function licz($co)
  20. {
  21. for($a=0;$a<=100;$a++)
  22. {//echo_($a);
  23. $thread = new CheckIpThread($co+$a);
  24. $threads []= $thread;
  25. $thread->start();
  26. }
  27. foreach ($threads as $thread) {
  28. $thread->join();
  29. }
  30.  
  31. foreach ($threads as $thread) {
  32. echo_($thread->data);
  33. }
  34. }
  35.  
  36.  
  37. function th($wsad)
  38. {return $wsad;//jakies tam obliczenia
  39. }
  40.  
  41. function echo_($tekst,$def=0)
  42. {
  43. flush();
  44. usleep(200);
  45. if($def===0)
  46. {var_dump($tekst);}
  47. if($def===1)
  48. {echo($tekst);}
  49. echo"</br>";
  50.  
  51.  
  52. }
  53. ?>

Kod wypluwa liczby od 0 do 799 i przestaje dalej sie wykonywać cały czas przegladarka "kręci" i na tym sie temat kończy.
O co kaman?

Ten post edytował sasiadstar 14.08.2017, 13:32:55
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 22.08.2025 - 08:16