Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:38643 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 14925 invoked from network); 26 Jun 2008 18:38:42 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Jun 2008 18:38:42 -0000 Authentication-Results: pb1.pair.com header.from=chris_se@gmx.net; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=chris_se@gmx.net; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmx.net designates 213.165.64.20 as permitted sender) X-PHP-List-Original-Sender: chris_se@gmx.net X-Host-Fingerprint: 213.165.64.20 mail.gmx.net Linux 2.5 (sometimes 2.4) (4) Received: from [213.165.64.20] ([213.165.64.20:47492] helo=mail.gmx.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CE/73-17914-032E3684 for ; Thu, 26 Jun 2008 14:38:41 -0400 Received: (qmail invoked by alias); 26 Jun 2008 18:38:37 -0000 Received: from p54A16787.dip.t-dialin.net (EHLO chris-se.dyndns.org) [84.161.103.135] by mail.gmx.net (mp053) with SMTP; 26 Jun 2008 20:38:37 +0200 X-Authenticated: #186999 X-Provags-ID: V01U2FsdGVkX1+1c/VTsB21H25s4mff3hy6+qwsLYiUE1NBDR3Qak TnE4AB+3VwFduy Received: from [192.168.0.175] (HSI-KBW-091-089-005-213.hsi2.kabelbw.de [91.89.5.213]) by chris-se.dyndns.org (Postfix) with ESMTP id 6F1AD10B8D; Thu, 26 Jun 2008 20:21:46 +0200 (CEST) Message-ID: <4863E1F3.4070706@gmx.net> Date: Thu, 26 Jun 2008 20:37:39 +0200 User-Agent: Thunderbird 2.0.0.14 (X11/20080421) MIME-Version: 1.0 To: Mangol Smith CC: PHP Internals References: In-Reply-To: X-Enigmail-Version: 0.95.6 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Y-GMX-Trusted: 0 Subject: Re: [PHP-DEV] Using Network functions. From: chris_se@gmx.net (Christian Seiler) Hi! > 2. What does streams has to do with this networking? Can it be done using > streams? Yes, it can. Take the following simple, incomplete example without much error handling as a starting point: // in the header #include "php_streams.h" // PHP function: PHP_FUNCTION(simplehttp_fetch) { php_stream *stream; struct timeval tv; int err; char *errstr; char buf[8192]; tv.tv_sec = 30; tv.tv_usec = 0; stream = php_stream_xport_create("tcp://www.google.com:80", sizeof("tcp://www.google.com:80")-1, ENFORCE_SAFE_MODE | REPORT_ERRORS, TREAM_XPORT_CLIENT | STREAM_XPORT_CONNECT, NULL, &tv, NULL, &errstr, &err); if (stream == NULL) { php_error(E_WARNING TSRMLS_CC, "unable to connect to tcp://www.google.com:80: %s", errstr == NULL ? "unknown error" : errstr); RETURN_NULL(); } php_stream_write(stream, "GET / HTTP/1.0\r\nHost: www.google.com\r\n\r\n", sizeof("GET / HTTP/1.0\r\nHost: www.google.com\r\n\r\n")-1); memset(buf, 0, 8192); php_stream_read(stream, buf, 8191); php_stream_close(stream); RETURN_STRING(buf, 1); } Basically, you want to look at main/php_streams.h and main/streams/php_stream_transport.h in the PHP source code. Userland fsockopen() essentially maps to php_stream_xport_create() and userland fread, fwrite, close, etc. essentially map to php_stream_read(), php_stream_write, php_stream_close, etc. Regards, Christian