Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: fsockopen() + fgets
Forum PHP.pl > Forum > PHP
Szakal
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 questionmark.gif

Prosze o pomoc
sf
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.
Szakal
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 :/ sad.gif
darkspirit
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 :/ sad.gif

Parametr długości od php 4.2.0 jest(stał się - jak kto woli 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 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 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` smile.gif

bye
Vengeance
bo przez fgets można pobierać dane z plików, z socketa albo nawet z stdin
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.