मैं 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
जानकारी के लिए धन्यवाद। क्या आपको लगता है कि कॉलबैक ट्रिगर करने के लिए stream_socket_client() के लिए यह समझ में आएगा? शायद मैं एक बग रिपोर्ट दर्ज करूंगा। – macinjosh
मुझे आपको एक निश्चित उत्तर देने के लिए नोटिफ़ायर के बारे में पर्याप्त जानकारी नहीं है। हो सकता है कि वे केवल प्रोटोकॉल रैपर के लिए (किसी कारण से) हैं। लेकिन कम से कम php_stream_notify_info और php_stream_notify_error अच्छा होगा। – VolkerK