2009-08-24 7 views
5

मैं PHP स्ट्रीम के साथ खेल रहा हूं और यहां दिखाए गए वर्ग को लिखने के लिए प्रयोग कर रहा हूं। कम से कम कहने के लिए PHP क्षेत्र इस क्षेत्र में थोड़ा दुबला हैं।PHP स्ट्रीम अधिसूचना कॉलबैक शामिल नहीं

मुझे कॉलबैक विधि निर्दिष्ट करने के लिए मेरा स्ट्रीम संदर्भ प्राप्त करने में एक कठिन समय है। यदि मैं किसी सॉकेट से कनेक्ट करने के लिए file_get_contents या fopen जैसे फ़ंक्शन का उपयोग करता हूं तो कॉलबैक लागू किया जाता है, लेकिन यदि मैं stream_socket_client का उपयोग नहीं करता हूं।

मुझे लगता है कि यह पर संदर्भ पारित कर रहा है और यदि मैं stream_socket_recvfrom का उपयोग करता हूं तो मुझे सॉकेट से वापस वही स्ट्रिंग मिलती है क्योंकि fgets वापस आ जाएंगे।

प्रासंगिक PHP दस्तावेज़ पोस्ट के अंत में जुड़े हुए हैं।

class IMAP { 

    // Connection Parameters 
    private $host; 
    private $port; 
    private $timeout; 

    // Credentials 
    private $email; 
    private $password; 

    private $client; 
    private $transcript; 

    function __construct($connection, $credentials) { 

     // Set Connection Settings 
     $this->host = $connection['host']; 
     $this->port = $connection['port']; 
     $this->timeout = $connection['timeout']; 

     // Set Credentials 
     $this->email = $credentials['email']; 
     $this->password = $credentials['password']; 

     // Connect to the IMAP server 
     $params = array('notification'=>array($this, 'getLine')); 
     $ctx = stream_context_create(); 
     stream_context_set_params($ctx, $params); 
     $this->client = stream_socket_client("tcp://$this->host:$this->port",$errno, $errstr, $this->timeout, STREAM_CLIENT_CONNECT, $ctx); 
     stream_socket_sendto($this->client, "a001 NOOP\r\n"); 

    } 

    function getLine($notification_code, $severity, $message, $message_code, $bytes_transferred, $bytes_max) { 
     $args = func_get_args(); 
     var_dump($args); 
    } 
} 

$connection = array(
    'host' => 'somehost', 
    'port' => 143, 
    'timeout' => 10 
); 

$credentails = array(
    'email' => 'someemail', 
    'password' => 'somepassword' 
); 

$imap = new IMAP($connection, $credentails); 

?> 

http://us3.php.net/manual/en/function.stream-context-set-params.php http://us3.php.net/manual/en/context.params.php

मैं भी यह कुछ हद तक संबंधित पीएचपी बग रिपोर्ट में पाया गया, लेकिन ऐसा लगता रिपोर्ट की तरह व्यर्थ था:

http://bugs.php.net/bug.php?id=42387&edit=1

उत्तर

5

ऐसा लगता है कि यह द्वारा समर्थित नहीं है php 5.3.0 के रूप में सॉकेट स्ट्रीम।

एकमात्र फ़ंक्शन जिसे मैं नोटिफ़ायर फ़ंक्शन (सी कोड में) कह सकता हूं वह मुख्य/स्ट्रीम/streams.c में php_stream_notification_notify है। वहाँ भी कुछ #defines

#define php_stream_notify_info 
#define php_stream_notify_progress 
#define php_stream_notify_progress_init 
#define php_stream_notify_progress_increment 
#define php_stream_notify_file_size 
#define php_stream_notify_error 

जो एक कॉल करने के लिए नीचे उबाल php_stream_notification_notify कर रहे हैं। एफटीपी रैपर उदा। कॉल

php_stream_notify_info(context, PHP_STREAM_NOTIFY_CONNECT, NULL, 0); 

php_ftp_fopen_connect में। कर्ल और http wrapper के साथ ही। लेकिन stream_socket_client() या संबंधित कार्यों के लिए ऐसी कोई कॉल नहीं है। और उदाहरण http://php.net/function.stream-notification-callback पर काम नहीं करते हैं यदि आप प्रोटोकॉल रैपर को परिवहन जैसे टीसीपी द्वारा प्रतिस्थापित करते हैं: (या यहां तक ​​कि फ़ाइल :)।

+0

जानकारी के लिए धन्यवाद। क्या आपको लगता है कि कॉलबैक ट्रिगर करने के लिए stream_socket_client() के लिए यह समझ में आएगा? शायद मैं एक बग रिपोर्ट दर्ज करूंगा। – macinjosh

+0

मुझे आपको एक निश्चित उत्तर देने के लिए नोटिफ़ायर के बारे में पर्याप्त जानकारी नहीं है। हो सकता है कि वे केवल प्रोटोकॉल रैपर के लिए (किसी कारण से) हैं। लेकिन कम से कम php_stream_notify_info और php_stream_notify_error अच्छा होगा। – VolkerK

संबंधित मुद्दे