How does PHP's function xmlrpc_encode_request() work?
Does it need the value of allow_url_fopen set to true?
Well, you access external URLs with this function, so does it need this configuration? I can't test it myself at the moment, unfortunately.
Thanks in advance!
No, it does not. This function is just for marshalling the requested function name and its parameters. It builds an XML string. Therefore it does not need to retrieve external URLs itself.
So this function in itself is not particular useful. Later on you will need to send the XML-encoded RPC request over an HTTP stream. And in this step 2, you need either allow_url_fopen, the curl extension, or the pecl http functions. Most XML-RPC libraries however provide a means to transmit the RPC request in HTTP via PHPs native socket functions.
So in essence, allow_url_fopen is not required.
Related
I am currently writing my own server in C++ for Posix systems. Before anyone says anything about how I should really use a prebuilt server, please be aware that I do use prebuilt servers for anything business related. This project is entirely a learning experience.
I would like this system to support server side scripting as well as static hosting. I run into a problem when I try to include support for the most important server side scripting language: PHP.
Standard PHP provides several predefined variables that give access to information about an incoming request. It also provides standard HTTP functions that interact with the request in specific ways. Further, it is supposed to be possible to perform IO operations on the request and response bodies by using the filenames php://input and php://output respectively to refer to the appropriate socket and permissions.
I know that I would be able to define all these variables and implement all these functions myself in the top of a wrapper script and then use include to run the user's script in the same context, but that seems cumbersome. I also have no idea how to map php://input or php://output to the actual request socket's file descriptor.
I don't know much about PHP interpreters. Is there a way to provide essential request data (user-agent, INET address, method, URI, version, headers, socket file descriptor, and maybe something I'm forgetting) to the PHP interpreter to be able to access the native definitions and implementations of these variables and functions? Or is it standard practice for the author of the server to define and implement these himself?
Most important, if I do have to implement these things myself, how do I map php://input and php://output to the correct file descriptor and permissions?
Thanks to everyone. Any help is appreciated.
Is it possible to pass variables from one webserver to another using php? I need to be able to pass variables from a webhost to a local server for processing and I dont know if it can be done.
You have to communicate between the servers somehow. How you do that communication determines if, and how, you would pass data. (You can't generally pass actual variables, just the contents of them).
If, for instance, you were communicating with HTTP then you could pass the data in the query string of the URI, or in the body of a POST request.
Post a web request to that server.
You can do that using curl and add header data or post data too.
Check php curl manual
Simple post request will also do the trick.
There are many ways you could do this. The simplest way and most service oriented would be to make a "catcher" php script which will recieve the variables on the target server and then the local server can run:
file_get_contents('http://targetserver.com/catcher.php?var1=val1&var2=val2&var3=val3...');
also look into sockets and direct connections, FTP, and other ways to do it.
I am trying to use the XMLWriter class in PHP to generate XML. I am working in CodeIgniter. When I try to output XML, I get this error (HTTP wrapper does not support writeable connections). What does it mean and what do I need to do to fix it? I am using this class here: http://www.phpbuilder.com/board/showthread.php?t=10356853.
What's your output call look like? That error usually means you're trying to save to an http url, e.g. like:
$myobj->save('http://example.com/path/file.xml');
which generally will fail. This requires an HTTP upload, but provides none of the specifics necessary to perform one. Should it be a PUT? A POST? What's the fieldname the receiving server is expecting? etc...
I know that this is a simple question for PHP guys but I don't know the language and just need to do a simple "get" from another web page when my page is hit. i.e. signal the other page that this page has been hit.
EDIT: curl is not available to me.
If curl wrappers are on (they are per default), you can use:
file_get_contents('http://www.example.org');
Note that this happens synchronous, so before the request has completed, your page won't either. It would be better to log access to a logfile (or database) and export the data occasionally. Alternatively, you could do the request after your page has completed, and output has been sent to the client.
Beware file_get_contents() and fopen():
If PHP has decided that filename specifies a registered protocol, and that protocol is registered as a network URL, PHP will check to make sure that allow_url_fopen is enabled. If it is switched off, PHP will emit a warning and the fopen call will fail.
There's numerous ways... the simplest is file_get_contents('http://...');
Other functions like fopen() also support http: streams.
If you need more control, I'd suggest looking at curl (see curl_init)
There are a number of ways to send a GET request with PHP. As mentioned above, you can use file_get_contents, fopen or cURL.
You can also use the HTTP extension, the fsockopen() function or streams via fopen.
I'd advise checking out what WordPress has done, as it handles almost all possibilities.
You'll probably want to use cURL
I want to have a PHP script send a XML formatted string to another PHP script that resides on a different server in a different part of town.
Is there any nice, clean way of doing this?
(PHP5 and all the latest software available)
check out cURL for posting data between pages.
If it were me, I would just POST the xml data to the other script. You could use a socket from PHP, or use CURL. I think that's the cleanest solution, although SOAP is also viable if you don't mind the overhead of the SOAP request, as well as using a library.
I strongly suggest rolling your own RESTful API and avoiding the complexity of SOAP altogether. All you need is the curl extension to handle the HTTP request/response, and simple_xml to build/process the XML. If your data is in a reasonable format, it should be easy for you to push it into an XML string and submit it as a POST to the other server. That server will respond to the request by reading the XML string from the POST var back into an object, and voila! It shouldn't take you all day to whip this out.
XML-RPC or SOAP or just a RESTful API
You can use cURL (complex API), the http extension (cleaner), or if you need to do more complex stuff you can even use the Scriptable Browser from simpletest.