CakeFest 2024: The Official CakePHP Conference

socket_set_nonblock

(PHP 4 >= 4.1.0, PHP 5, PHP 7, PHP 8)

socket_set_nonblockBelirtilen dosya tanıtıcısı için beklememe kipini etkinleştirir

Açıklama

socket_set_nonblock(Socket $soket): bool

soket ile belirtilen sokete O_NONBLOCK seçeneğini atar (beklememe kipini etkin kılar; başka bir deyişle soketi engellenmeyen kipe sokar).

Bir engellenmeyen soket üzerinde yapılan işlemler (bağlanma, kabul, alım, gönderim gibi) sırasında bir sinyal gelmedikçe, okunacak veri yoksa veya veri yazılamıyorsa betik işlemin başlamasını beklemez ve böyle bir durumda ilgili işlev çağrısı (bu işlev değil) başarısız olur.

Bağımsız Değişkenler

soket

socket_create() veya socket_accept() ile oluşturulmuş geçerli bir Socket örneği.

Dönen Değerler

Başarı durumunda true, başarısızlık durumunda false döner.

Sürüm Bilgisi

Sürüm: Açıklama
8.0.0soket artık bir Socket örneği olabiliyor; evvelce resource türündeydi.

Örnekler

Örnek 1 - socket_set_nonblock() örneği

<?php
$soket
= socket_create_listen(1223);
socket_set_nonblock($soket);

socket_accept($soket);
?>

Bu örnekte, tüm arabirimlerin 1223. portunda bir dinleme soketi oluşturulmakta ve soket beklememe kipine (O_NONBLOCK) alınmaktadır. Bu anda bekleyen bir bağlantı yoksa socket_accept() bir zamanaşımı beklemeksizin başarısız olur.

Ayrıca Bakınız

add a note

User Contributed Notes 1 note

up
3
kpobococ at gmail dot com
14 years ago
Beware, when using this function within a loop (i.e. a demon with a socket). The socket_accept(), for example, emits a warning each time there is no incoming connection available to be read. My php error log file got huge in a matter of seconds, eventually crashing the server.

Of course, i used the @ before the function to take care of that problem.

[EDITOR: One can (and should) use socket_select to detect a new connection on a socket (it's a "readable" event)]
To Top