Hey guys,
I just started hacking PHP. I want to use Netwok Functions.
So far from the source code browsing I learnt that In PHP "obvious"
solution is not the right answer.
The obvious solution for implementing HTTP methods or any Network functions
for that matter, is using socket(), connect(), send(), recv() with
appropriate HTTP request which only works for *NIX systems. So, there must
be some kind of wrappers over it make these Platform Independent.
Though, I looked into the implementations of
PHP_FUNCTION('php_get_contents'). I didn't get much of it. I din't see any
socket functions in its implementation. I saw some kind of stream_*
functions. (which was complete abstract to me).
- Can any one help me in using Network functions?
- What does streams has to do with this networking? Can it be done using
streams? - In List of Supported
Protocols/Wrappershttp://in2.php.net/manual/en/wrappers.phpits
mentioned that
Allows read-only access to files/resources via HTTP 1.0, using the HTTP GET
method. This means isn't there any wrapper to use all HTTP methods. I'm
concerned about HTTP PUT/POST (esp. PUT) method. How can I use that method? - what are the other alternatives (if any)?
Hey guys,
someone suggested me to have a look at libcURL. I did, but its very complex.
All I needed is lowlevel/network wrappers.
like emalloc() & pemalloc() as wrapper on malloc(). There might be some
wrappers (platform independent & used in php source code) which I can use to
make a connection and then send HTTP requests.
I hope this will be the simplest method.
On Wednesday 25 June 2008 6:22:22 pm Mangol Smith wrote:
Hey guys,
someone suggested me to have a look at libcURL. I did, but its very
complex.All I needed is lowlevel/network wrappers.
like emalloc() & pemalloc() as wrapper on malloc(). There might be some
wrappers (platform independent & used in php source code) which I can use
to make a connection and then send HTTP requests.I hope this will be the simplest method.
Why do you need raw string level control over the HTTP request? Wouldn't it
be easier to use something that will handle all of the thousand edge cases
and locking for you? (That is, I think, part of the meaning behind the
obvious solution, write to a socket yourself, not being the right solution,
letting someone else do the hard stuff for you.)
--
Larry Garfield
larry@garfieldtech.com
Hi,
If you want to POST or do weird HTTP stuff, try the Curl extension.
(Multiple platforms)
Also look into PEAR, they have some socket stuff as well I think, as
well as lots of other extensions that implement other protocols.
But, doesn't this make my extension depend on Curl or any PEAR extension you
are talking about? That is what I wan't to avoid.
On Thu, Jun 26, 2008 at 8:27 AM, Larry Garfield larry@garfieldtech.com
wrote:
Why do you need raw string level control over the HTTP request? Wouldn't
it
be easier to use something that will handle all of the thousand edge cases
and locking for you?
Yeah, might be the only thing I want to avoid is my extension depending on
other non standard (which are not shipped with PHP by default) extensions.
Thats why I'm looking for lower level wrappers. Thats why I feel using CORE
API.
W liście Mangol Smith z dnia czwartek 26 czerwca 2008:
But, doesn't this make my extension depend on Curl or any PEAR extension
you are talking about? That is what I wan't to avoid.
Are you sure you even need to write your own extension? If you just want to do
HTTP requests, then curl or HTTP extension should be sufficient.
--
Paweł Stradomski
Are you sure you even need to write your own extension? If you just want to
do
HTTP requests, then curl or HTTP extension should be sufficient.
Nope, I'm developing an extension. In which I require this functionality.
Its not the entire purpose of my extension. Just a part of the
functionality.
Mangol Smith escribió:
Hey guys,
someone suggested me to have a look at libcURL. I did, but its very complex.
All I needed is lowlevel/network wrappers.
like emalloc() & pemalloc() as wrapper on malloc(). There might be some
wrappers (platform independent & used in php source code) which I can use to
make a connection and then send HTTP requests.
use the api provided by either pecl_http or curl extension, you dont
reaaly want to do it in a different way.
also. evaluate if you realy want to write a C extension for that, proper
userspace code should do the trick just fine.
--
"Perhaps, my biggest pet peeve pertaining to safe_mode is that it is not
really safe,
merely offering an illusion of safety that does not stand to closer
examination" - Ilia on PHP safe_mode
Cristian Rodríguez R.
Platform/OpenSUSE - Core Services
SUSE LINUX Products GmbH
Research & Development
http://www.opensuse.org/
Hi!
- 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