downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Libevent 関数> <定義済み定数
Last updated: Fri, 13 Nov 2009

view this page in

例1 基本 API による STDIN のポーリング

<?php

function callback_func($fd$events$arg)
{
    static 
$max_requests;

    
$max_requests++;

    if (
$max_requests == 10) { /* 10 回書き込んだらループを抜けます */
        
event_base_loopexit($arg[1]);
    }

    
/* 読める限り読み込みます */
    
while (false !=== ($data fread($fd4096))) {
        echo 
$data;
    }
}

/* ベースとイベントを作成します */
$base event_base_new();
$event event_new();

$fd STDIN;

/* イベントフラグを設定します */
event_set($event$fdEV_READ EV_PERSIST"callback_func", array($event$base));
/* イベントベースを設定します */
event_base_set($event$base);

/* イベントを有効にします */
event_add($event);
/* イベントループを開始します */
event_base_loop($base);

?>

例2 バッファイベント API による STDIN のポーリング

<?php

function callback_func($buf$arg)
{
    static 
$max_requests;

    
$max_requests++;

    if (
$max_requests == 10) {
        
event_base_loopexit($arg);
    }

    
/* 読める限り読み込みます */
    
while (false !=== ($data event_buffer_read($buf10))) {
        echo 
$data;
    }
}

function 
error_func($buf$what$arg)
{
    
/* エラーを処理します */
}

$base event_base_new();
$b event_buffer_new(STDIN"callback_func"NULL"error_func"$base);

event_buffer_base_set($b$base);
event_buffer_enable($bEV_READ);

event_base_loop($base);

?>



add a note add a note User Contributed Notes
There are no user contributed notes for this page.

Libevent 関数> <定義済み定数
Last updated: Fri, 13 Nov 2009
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites