lstrojny / fxmlrpc Goto Github PK
View Code? Open in Web Editor NEWA modern, super fast XML/RPC client for PHP >=5.6
A modern, super fast XML/RPC client for PHP >=5.6
Would you be so kind to create a new release with the updated dependencies that are already in master? The last release was on 2021.
Thank you in advance.
First I would like to say thanks for the awesome XMLReader implementation you've written. Is it possible that you also add the code to parse incoming XML requests?
<?xml version="1.0"?>
<methodCall>
<methodName>method.to.call</methodName>
<params>
<param>
<value><i4>41</i4></value>
</param>
</params>
</methodCall>
What do you think about implement method like __getLastRequest
and __getLastResponse
- like in SoapClient
- to fast returning raw XML. Now you couldn't look for these info.
What case?
$client = new Client($url);
$result = $client->call('Execute', [1, 2, 3]);
print_t($client->getLastRequest());
Currently working with an API that is returning some values like
<member>
<name>msg</name>
<value></value>
</member>
and the parser is throwing the unexpectedTag exception. Surely this just wants to parse that element as an empty value rather then throwing an unexpected tag?
Full exception message is "Invalid XML. Expected one of "array", "#text", "string", "struct", "int", "biginteger", "i8", "i4", "i2", "i1", "boolean", "double", "float", "bigdecimal", "dateTime.iso8601", "dateTime", "base64", "nil", "dom", got "value" on depth 9 (context: "")"
Any chance to get support for the artax http client?
Would be nice to have a decorator for HTTP transports, so that writting decorators is easier. Current use case: Authentication decorator, which sets some header in the constructor, otherwise it behaves like the underlying transport.
Some XMLRPC endpoints require request's Content-Type set to "text/xml" or will return a 400 response code.
As this lib is aimed at sending and receiving XML entities, it should set content type regardless of transport used
(having this issue with Gandi API : http://doc.rpc.gandi.net/overview.html#client)
I don't think it needs a description ;)
I am working with your package for a long time now, so I have some experience with it. I created a few clients implementing ClientInterface
and I hardly ever used methods other than call
and multicall
. The rest of methods seems to me an implementation detail, which might be useful in the default client, but makes implementing the interface harder. So I am suggesting a BC breaking and a non BC breaking solution to make things cleaner:
What do you think? (It also follows the single responsibility principle by splitting into a callable and a configurable interface)
I've just run into a situation where under certain circumstances the response coming back from an (alleged) XMLRPC server is not XML, but simply a string containing an error message. \fXmlRpc\Client::call currently just returns null from this request, but ideally it would throw an exception and have some way to get access to the string that came through in the response.
I understand that you might want to assume the URL being called will always return XML, though having some way to handle the cases when a URL is wrong might be handy. If you can suggest some other way to handle this, I'm open to ideas.
(It's a Magento store, in case you're interested, and the error occurs in certain versions where the URL for the XMLRPC interface has to be slightly tweaked)
zend-diactoros is abandoned, alternatives should be recommended
Hello,
I found something very interesting and I even don't know and not sure if it is a bug or this is how it supposed to work.
When having an array with one key that is integer but not 0 - zero ,
it converted to xml array with data-values,
instead of been struct with member node.
example:
array (
0 => 'something',
1 => '15632',
2 => 1395,
3 => '25/05/2021',
4 => array (
4035 => array (
0 => 3600,
1 => 3700,
2 => 4200,
),
),
)
see the 4035 key that in this case represent an id of something, and holds list values.
the output xml of this part is:
<?xml version="1.0" encoding="UTF-8"?><methodCall><methodName>update_plan_prices</methodName><params><param><value><string>something</string></value></param><param><value><string>15632</string></value></param><param><value><int>1395</int></value></param><param><value><string>25/05/2021</string></value></param><param><value><array><data><value><array><data><value><int>3600</int></value><value><int>3700</int></value><value><int>4200</int></value></data></array></value></data></array></value></param></params></methodCall>
instead of been converted to:
<?xml version="1.0" encoding="UTF-8"?><methodCall><methodName>update_plan_prices</methodName><params><param><value><string>something</string></value></param><param><value><string>15632</string></value></param><param><value><int>1395</int></value></param><param><value><string>25/05/2021</string></value></param><param><value>**<struct><member>**<name>4035</name><value><array><data><value><int>3600</int></value><value><int>3700</int></value><value><int>4200</int></value></data></array></value>**</member></struct>**</value></param></params></methodCall>
I assume it is happening in this part if I'm using XmlWriterSerializer
https://github.com/lstrojny/fxmlrpc/blob/master/src/fXmlRpc/Serializer/XmlWriterSerializer.php#L138
and also if use the NativeSerializer
https://github.com/lstrojny/fxmlrpc/blob/master/src/fXmlRpc/Serializer/NativeSerializer.php
with the build in function xmlrpc_encode_request
https://www.php.net/manual/en/function.xmlrpc-encode-request.php
Because you are know using the ivory-http-adapter
as the default you should include this in your composer.json. Or you should have updated to a major version know i updated to the latest version and my installation is broken.
Hello all,
Start with Symfony log error:
[2013-09-30 11:30:17] request.CRITICAL: Uncaught PHP Exception fXmlRpc\Exception\RuntimeException: "Invalid XML. Expected one of "member", got "struct" on depth 7 (context: "")" at ...\vendor\lstrojny\fxmlrpc\src\fXmlRpc\Parser\XmlReaderParser.php line 81 {"exception":"[object](fXmlRpc\Exception\RuntimeException: Invalid XML. Expected one of "member", got "struct" on depth 7 %28context: ""%29 at ...\vendor\lstrojny\fxmlrpc\src\fXmlRpc\Parser\XmlReaderParser.php:81)"} []
And the response parsed
<?xml version='1.0'?>
<methodResponse>
<params>
<param>
<value>
<struct>
<member>
<name>a name</name>
<value><struct></struct></value>
</member>
</struct>
</value>
</param>
</params>
</methodResponse>
I would like to finalize this package soon:
https://github.com/fxmlrpc/serialization
What do you think about integrating it into this library afterwards? (extend/composition)
Seriously, it's so confusing that this package doesn't "just work".
Make zendframework/zend-diactoros, php-http/message and php-http/guzzle6-adapter dependencies please, so that if one removes fxmlrpc, these are also removed. It just makes no sense not to.
Please add Ivory Http Adapter dependency into composer.json.
Just curious as the reasoning behind this? I'm using __call() as a workaround for this for the time being, but it'd be easier to just extend the class and avoid the extra overhead.
Why Client
class has logic responsible for throwing exception when server return fault? It's little confusing for me, this is not responsibility of this class.
For me this exception should be thrown by parsers. And passing by reference could be removed.
For class NativeParser
line could be changed for:
throw ResponseException::fault($result);
For class XmlReaderParser
line could be set as internal variable and after all parsed document checked is fault was encountered and then throw exception.
After upgrading to 0.9.5 from 0.9.4:
( ! ) Fatal error: Class 'Ivory\HttpAdapter\HttpAdapterFactory' not found in ..../vendor/lstrojny/fxmlrpc/src/fXmlRpc/Client.php on line 75
The following code will cause fxmlrpc to hang with max processor usage (using composer):
<?php
require '../vendor/autoload.php';
$client = new \fXmlRpc\Client("http://localhost/");
$result = $client->call('Reserve', [["_FCGI_" => "some value"]]);
Looking at the code, it seems to be the array/struct detection code (line 146-157 in XmlWariterSerializer). When $a = '_FCGI_'
, the ++$a
will never change, causing an infinite loop. I'm currently working around this by using ext/xmlrpc which doesn't exhibit the issue.
I found this when running PHP 5.6.2, non-thread safe, 64 bit under IIS 7.5 & 8.5 with fastcgi, and it's the fastcgi $_SERVER
keys that look like this. The issue happens when running from the PHP built-in web server as well.
Currently the HttpAdapterInterface is used as a dependency in HttpAdapterTransport.
We could probably rely on PsrHttpAdapterInterface (introduced in 0.8 development branch) which is a parent of HttpAdapterInterface. However in this case we would have to construct Request objects instead of calling $adapter->post
. It adds complexity, but allows users to use a wider set of implementations.
@lstrojny what do you think about fix all code (src and tests) via php-cs-fixer using PSR-2
standard?
I think this will be good practice and make code more beautiful (now is very good, but can be better as allways 😄) than now.
Command should looks:
php-cs-fixer fix src/ --level=psr2
Links to php-cs-fixer plugin:
https://github.com/FriendsOfPHP/PHP-CS-Fixer
http://cs.sensiolabs.org/
The example for Guzzle 4+ is not working, because you need to use \Ivory\HttpAdapter\GuzzleHttpHttpAdapter instead of \Ivory\HttpAdapter\GuzzleHttpAdapter
The benchmark folder includes a 6 MB XML file, is it really necessary to include this in the composer package?
I've ran into Fatal error: Uncaught RuntimeException: Puli Factory is not available in /localhost/vendor/php-http/discovery/src/ClassDiscovery.php:32
after installing your library via composer require lstrojny/fxmlrpc
and trying to run the basic example:
require_once dirname(__FILE__) . '/vendor/autoload.php';
$client = new \fXmlRpc\Client('http://endpoint.com');
$client->call('remoteMethod', array('arg1', true));
It seems that PULI_FACTORY_CLASS
is not available. Any ideas on how to fix this issue?
Under "How fast is it really?" it says this is only 2x slower then xmlrpc but with my data I am seeing it being 12x slower.
Here is an issue I logged on the official Infusionsoft PHP API repository about this problem:
infusionsoft/infusionsoft-php#229
I highly recommend trying the NativeParser out if you want to improve speed and have access to install xmlrpc.
Hi,
I saw that the requirement in composer.json
is ~7.1
.
Any plan to support php 8 ? What are the blockers ?
Thanks.
Hi, I'm facing with a probem when some of the XML's can't be parsed by XmlReaderParser.
For examlpe this XML string is valid, bat XmlReaderParser return null:
This is my code:
$xmlParser = new \fXmlRpc\Parser\XmlReaderParser();;
$res = $xmlParser->parse($xmlString);
and this is a XML:
<?xml version='1.0'?>
<methodResponse>
<params>
<param>
<value><array><data>
<value><string>expected string or buffer
2015-07-30 16:19:22:INFO: [�[1m�[91mThreadID: 1�[0m �[1m�[92m - ChannelWorker�[92m�[0m] https://www.googleapis.com/youtube/v3/channels?managedByMe=true&onBehalfOfContentOwner=12345&maxResults=50&pageToken=CPa8AxAA&part=snippet%2CcontentDetails%2CtopicDetails%2Cstatistics%2CcontentOwnerDetails&key=1234�[0m
2015-07-30 16:19:22:INFO: [�[1m�[96mAccess key: 12321123 [0m]
</string></value>
<value><int>68231371</int></value>
<value><boolean>1</boolean></value>
</data></array></value>
</param>
</params>
</methodResponse>
What is the problem, or maybe I doing something wrong?
Using the arguments I can implement XML-RPC server based authentication by passing username/password arguments to the call. How can I implement HTTP-based authentication?
Since the transport is a private property of the client I cannot access it, howerver I only want take care of an injected ClientInterface
. So the actual question: If I have a Client object, how can I make it send HTTP Authorization header?
Some package improvements I would do:
.editorconfig
file for making compatible IDEs follow conventions.Sample content:
root = true
[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[composer.json]
indent_style = space
indent_size = 4
[*.php]
indent_style = space
indent_size = 4
[*.yml]
indent_style = space
indent_size = 2
.scrutinizer.yml
file, to customize tests and ignore tests/
directory.Sample content:
filter:
paths: [src/*]
tools:
php_analyzer: true
php_mess_detector: true
php_pdepend: true
external_code_coverage:
timeout: '600'
Sample content:
language: php
php:
- 5.4
- 5.5
- 5.6
- hhvm
before_script:
- travis_retry composer self-update
- travis_retry composer install --prefer-source --no-interaction
- npm install
script: phpunit
after_script:
- if [[ "$TRAVIS_PHP_VERSION" != "hhvm" ]]; then wget https://scrutinizer-ci.com/ocular.phar; fi
- if [[ "$TRAVIS_PHP_VERSION" != "hhvm" ]]; then php ocular.phar code-coverage:upload --format=php-clover build/coverage.xml; fi
(Of course it needs a phpunit configuration generating coverage)
If you like any of these, I am happy to open a PR.
Packagist package is still at 0.14.1. I think the hook is broken.
I know it is a big change/BC break, but I see no real need for maintaining a http adapter inside this package. Here is a quite good HTTP adapter package, under heavy development, but stable enough to use. Geocoder 3 will be released using this under the hood.
What do you think?
As you can set the HTTP charset on the transport, shouldn't you also be able to set XML encoding on the serializers/parsers?
It is hard coded to UTF-8 here:
NativeSerializer
XmlWriterSerializer
NativeParser
XmlReaderParser
I don't know if any XmlRpc server or client would break down if you mix HTTP charset and XML encoding, but better safe than sorry?
I suggest adding a setEncoding to ParserInterface and SerializerInterface.
Encoding could also be set according to the HTTP charset and defaulted to UTF-8 if no HTTP charset is available?
What do you think?
The switch from message-factory in favour of psr factory #86 breaks the requests in the HttpAdapterTransport
since headers and body are no longer correctly set.
public function send($endpoint, $payload)
{
try {
$request = $this->messageFactory->createRequest(
'POST',
$endpoint,
['Content-Type' => 'text/xml; charset=UTF-8'],
$payload
);
The PSR 17 request factory doesn't take headers or body as arguments and they need to be set manually with methods on the request object.
<?php
namespace Psr\Http\Message;
interface RequestFactoryInterface
{
/**
* Create a new request.
*
* @param string $method The HTTP method associated with the request.
* @param UriInterface|string $uri The URI associated with the request. If
* the value is a string, the factory MUST create a UriInterface
* instance based on it.
*
* @return RequestInterface
*/
public function createRequest(string $method, $uri): RequestInterface;
}
I'll work on a PR on Monday.
Hello,
I have manually downloaded it and played and looks very good in terms of speed and now I want to install it into my project. (vendor Folder)
I did not quite get how can I install it ? there is no composer installation for the project ?
Excellent library. No issues to report, just wanted to note that the library was super easy to implement in https://github.com/cpliakas/acquia-sdk-php which allowed us to replace our hacky custom XMLRPC stuff.
Great work,
Chris
We leverage this library in the Acquia SDK for PHP, and our automated tests are failing on PHP 5.5 with the error mentioned in the title of this issue. Tests pass using PHP 5.3 and 5.4. There are multiple builds where this is happening, but a specific build is at https://travis-ci.org/acquia/acquia-sdk-php/jobs/17426083.
If looks like the 0.9.0 release adopted a more terse method of initializing some properties as empty arrays that doesn't jive with 5.5. See
fxmlrpc/src/fXmlRpc/Client.php
Line 57 in 8435c58
private $prependParams = array();
syntax which seems to work across the board.
Let me know if you need more details or addition info.
Chris
Ivory is used but it's deprecated in favor of php-http.
Hi,
I cannot install guzzle6 adapter as it reqires httplug in version 2 or up, while the httpplug for fxmlrp is set to be below verion 2:
"php-http/httplug": "~1"
Can we use httplug in latest verion?
Hello! The recent release of version 7 of the Guzzle HTTP adapter has introduced direct support from the library for the PSR-18 (HTTP Client) standard. The folks at HTTPlug have said that they don't have immediate plans for adding support for Guzzle 7, since in the long term, the goal is to have PSR-18-compatible libraries just consumed directly, without need for a bridge layer.
Along with this, it would be mighty handy if we could implement an adapter that supports a PSR-17 (Request factory) and a PSR-18 HTTP client, allowing the removal of a fair number of intermediate bridge libraries. Ideally, just fXmlRpc, the PSR-17 request factory, and the PSR-18-implementing library itself would be required (the former and/or the latter requiring the PSR interfaces themselves).
If there's no opposition, I plan to begin working on a pull request for this shortly.
#36 fixed a large pain point when implementing this lib in an API SDK, and a release would allow usage of that via composer with ease.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.