Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> fsockopen() + fgets
Szakal
post
Post #1





Grupa: Zarejestrowani
Postów: 86
Pomógł: 0
Dołączył: 27.05.2004
Skąd: Zielona Góra

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


Witam!

Łącze się z napisanym przez siebie serwerem w sposób:

  1. <?php
  2.  
  3. $socket = @fsockopen(&#092;"localhost\",100,$errno,$errstr,10);
  4. echo fgets($socket,27);
  5. fputs($socket, &#092;"TIMErn\");
  6. echo fgets($socket,23);
  7.  
  8. ?>


Przy połączeniu niemam problemów z odbieraniem danych bo wiem ile maja znaków (27 - "WITAM - Połączenie otwarte").
Tak samo wysyłając zapytanie TIME.

Niestety niewszystkie odpowiedzi będą miały ściśle określona liczbę znaków, będzie ona dowolna (zależna od zawartości jakiegos pliku).

Moje dokładne pytanie to Jak pobrać wielkość aktualnie odebranej linijki z danymi (IMG:http://forum.php.pl/style_emoticons/default/questionmark.gif)

Prosze o pomoc
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 4)
sf
post
Post #2





Grupa: Zarejestrowani
Postów: 1 597
Pomógł: 30
Dołączył: 19.02.2003
Skąd: Tychy

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


Cytat
Note:  The length parameter became optional in php 4.2.0, if omitted, it would assume 1024 as the line length. As of php 4.3, omitting length will keep reading from the stream until it reaches the end of the line. If the majority of the lines in the file are all larger than 8KB, it is more resource efficient for your script to specify the maximum line length.
Go to the top of the page
+Quote Post
Szakal
post
Post #3





Grupa: Zarejestrowani
Postów: 86
Pomógł: 0
Dołączył: 27.05.2004
Skąd: Zielona Góra

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


Cytat(sf @ 2004-08-11 23:57:02)
Cytat
Note:  The length parameter became optional in php 4.2.0, if omitted, it would assume 1024 as the line length. As of php 4.3, omitting length will keep reading from the stream until it reaches the end of the line. If the majority of the lines in the file are all larger than 8KB, it is more resource efficient for your script to specify the maximum line length.

Wiele mi to niemówi :/ (IMG:http://forum.php.pl/style_emoticons/default/sad.gif)
Go to the top of the page
+Quote Post
darkspirit
post
Post #4





Grupa: Zarejestrowani
Postów: 19
Pomógł: 0
Dołączył: 13.08.2004
Skąd: Łódź

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


Cytat(Szakal @ 2004-08-12 14:06:05)
Cytat(sf @ 2004-08-11 23:57:02)
Cytat
Note:  The length parameter became optional in php 4.2.0, if omitted, it would assume 1024 as the line length. As of php 4.3, omitting length will keep reading from the stream until it reaches the end of the line. If the majority of the lines in the file are all larger than 8KB, it is more resource efficient for your script to specify the maximum line length.

Wiele mi to niemówi :/ (IMG:http://forum.php.pl/style_emoticons/default/sad.gif)

Parametr długości od php 4.2.0 jest(stał się - jak kto woli (IMG:http://forum.php.pl/style_emoticons/default/tongue.gif) ) optymalny(czytaj nie musisz go podawać!), jeśli go pominiemy będzie miał wartość 1024. Od php 4.3 jeżeli pominiemy parametr, php będzie czytało przekaz dopóki nie wyciągnie końca lini(wszyscy wiemy oco chodzi (IMG:http://forum.php.pl/style_emoticons/default/tongue.gif) )

to mnie ciekawi: If the majority of the lines in the file are all larger than 8KB
jeśli większość lini w twoim pliku jest większa niż 8KB(wydawało mi się, że mówimy o socketach a nie plikach (IMG:http://forum.php.pl/style_emoticons/default/graduated.gif) ) lepiej podać max. długość linii...

coś mi się wydaje, że ten cały quote był o plikach

[dop. do posta poniżej]
ano można o tym nie pomyślałem, przecież funkcja może mieć wiele `funkcji` (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)

bye

Ten post edytował darkspirit 13.08.2004, 17:41:29
Go to the top of the page
+Quote Post
Vengeance
post
Post #5





Grupa: Zarejestrowani
Postów: 657
Pomógł: 2
Dołączył: 15.08.2003
Skąd: Łódź

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


bo przez fgets można pobierać dane z plików, z socketa albo nawet z stdin
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 22.08.2025 - 22:27