Which XML-RPC Library? - php

There are at least two implementations of XML-RPC for PHP. Which is best and why?
I've been using the one based on Edd Dumbill's work in the O'Reilly jellyfish book, but I find it extraordinarily awkward and verbose and very hard to debug.
The version built into PHP looks a bit cleaner, but contains warnings that the extension is experimental.
Your favorite? A different one?

XML-RPC is mostly about marshalling data, so performance differences between the native PHP extension and pure PHP implementations is negligible. The PHP builtin is however just about encoding data, so you need an add-on API to actually send RPC calls.
UsefulIncs xmlrpc library was the one susceptible to eval exploits. So I'd eschew that regardless of what it looks today. Better use the native PHP xmlrpc_* functions and forget about the experimental tag.
An alternative would be Zend Frameworks XmlRpc functions, which are pure PHP code and overly verbose, but time-tested. Personally I once had a custom XML-RPC lib which also performed Content-Encoding et al, but today I'd use ZendFrameworks, HordeFramework or PEARs XMLRPC2. (But am glad we can mostly use JSON nowadays.)

The built-in version (xmlrpc-epi) works. It has some interesting bugs in older versions of PHP but you should be fine as of PHP 5.3.2. I've written a really simple library, called Ripcord, that uses the built-in version but works around the most annoying bugs in older PHP versions. See http://ripcord.googlecode.com/

Related

When to create a PHP extension?

In what exact use cases should a developer create a PHP extension instead of PHP library?
From what I found on google (very little is written on the subject).
PHP extensions are compiled libraries which enable specific functions to be used in your PHP code.
I also found that they are written in C.
Why should I compile a library?
What are the benefits over libraries?
If you could answer with an example, lets say zeroMQ or mySQL extension, that would be great.
Main point of writing extension in C instead of library in PHP is speed and/or memory-wise optimization. You can leverage C's means of optimizations, which are not available in PHP.
A good example here would be BC Math extension: most of the functionality could be written in pure PHP (although not all of it), but the main point here is the speed and memory-optimized computations.

Which mysql library is supported in php hiphop?

In regular php, there are multiple libraries for accessing mysql, such as mysql, mysqli, pdo and mysqlnd.
Which of these libraries are supported in php hiphop (https://github.com/facebook/hiphop-php/wiki/)?
Hiphip for PHP is not library/module specific. Built-in PHP modules are already written in C++ and compiled. You can write your own by hand. All that Hiphop for PHP does is automates that process for you. Since the built in modules are already compiled, Hiphop for PHP just ignores them. It has no bearing on what built-in libraries you can use in your code or what it works with.
The only place you may find issues with Hiphop for PHP is if you write closures or evals in your code. As of the last time I checked, Hiphop for PHP could not handle them. However, things may have changed since then.
EDIT:
Looks like interoperability with all built in functions was not fully implemented after all. Documentation and use of Hiphop is pretty minimal (as in you've already found it). You may just want to do some small tests to see if the libraries you want to use are supported. Do post the results back up here so others can benefit!
No php Hip-Hop does'nt support any of this libraries except PDO
I have also tried it but it did'nt work
For Further information please see below link:-
http://php.webtutor.pl/en/2011/05/10/hiphop-for-php-unimplemented-functions-and-features/

What are nice use cases for cURL in PHP?

It's evident that the cURL functions are very widely used. But why is that? Is it really only because the extension is mostly enabled per default?
While I can certainly relate to not introducing 3rd party libraries over builtins (DOMDocument vs phpQuery), using curl appears somewhat odd to me. There are heaps of HTTP libraries like Zend_Http or PEAR Http_Request. And despite my disdain for needless object-oriented interfaces, the pull-parameter-procedural API of curl strikes me as less legible in comparison.
There is of course a reason for that. But I'm wondering if most PHP developers realize what else libcurl can actually be used for, and that it's not just a HTTP library?
Do you have examples or actual code which utilizes cURL for <any other things> it was made for?
Or if you just use it for HTTP, what are the reasons. Why are real PHP HTTP libraries seemingly avoided nowadays?
I think this would be related to why do people use the mysql functions instead of mysqli (more object oriented interface) or take a step further and use a data abstraction layer or PDOs.
HTTP_Request2 says that there is a cURL adapter available to wrap around PHP's cURL functions.
Personally a lot of the PEAR extensions I have tried out, I haven't been that impressed with (and I feel less confident with PEAR libraries that are sitting in alpha that haven't been updated in a long time). Whereas the HTTP_Request2 Library does look quite nice
I for one would have used cURL without thinking of looking at a possible PEAR library to use. So thanks for raising my awareness.
The libraries you mentioned aren't default, and from my experience in PHP, I prefer to use less of such libraries; they enable a broader attack surface, decrease reliability, open to future modification/deprecation more than PHP itself.
Then, there's the sockets functionality which, although I've used some times, I prefer to rely on a higher level approach whenever possible.
What have I used CURL for?
As some may know, I'm currently working on a PHP framework. The communication core extension (appropriately called "connect") makes use of CURL as it's base.
I've used it widely, from extracting favicons form websites (together with parser utilities and stuff) to standard API calls over HTTP as well as the FTP layer when PHP's FTP is disabled (through stream wrappers) - and we all know native PHP FTP ain't that reliable.
Functional reasons as mentioned in the comments:
It's very old, [widely used and] well tested code, works reliably
is usually enabled by default
allows very fine grained control over the details of the request.
This might need expanding. By nature of the common-denominator protocol API cURL might provide features that plain HTTP libraries in PHP can't...
Historic reasons:
curl used to be the only thing that could handle cookies, POST, file uploads...
A lot of curl use probably comes from tutorials that pre-date PHP 5.

Convert a class to an extension

I have a PHP class I want to convert to a PHP extension. I checked some tutorials (tuxradar's writing extensions, php.net's extending php, and zend's extension writing) and it's a bit complicated.
I found the article "How to write PHP extensions" (ed note: site is defunct) and I wanted to know if it is possible to use this to make it grab a PHP class from a certain path (say /home/website1/public_html/api/class.php), execute it and return the class instance.
This way it will be usable in other websites that are hosted on the same server – each can simply call the function and it will obtain its own instance.
Is that possible?
The question as I understand it now is, The user has a PHP class that they would like to share with multiple people, but does not want to share the source code.
There are many solutions to this, they generally invovle turning the PHP code into some kind of byte code, and using a PHP extension to run the byte code. I've never used any of these solutions, but I'm aware of the following:
phc is an open source compiler for PHP
Zend Guard
HipHop for PHP - I'm unsure about this, but Facebook recently released it so it might be worth a look.
I'm sure there are others. Just Google for PHP Compiler, or PHP Accelerator.
In one sentence: I don't believe so, I think its a lot more work than that.
No, there is not tool that can do that.
Anyway, what you want call be easily accomplished with auto_prepend_file. Just make that ini directive point to a PHP file that has the class definition, and then it will be available to all the applications.
If you don't want the users to be able to use the source, you can use one the several zend extensions that allow you to pre-compile the file and use it in that form.
You can extend underlying C library functions into PHP space by writing PHP extensions. However, i think in your case you don't need to write one.
I am aware that this is an old question (being from 2012) however the answer has changed and there is now a tool that can do this. Jim Thunderbirds PHP-to-C Extension toolset provides the means to take a simple class in one file all the way up to a complicated multi file multi-level namespaced framework and convert it to a C-extension that can then be installed into your PHP server.
While in many use cases doing so is not needed as the ordinary PHP code will work just as good in some cases significant performance improvements can be experienced. The information page shows that an ordinary class (deliberately designed to take a long time) took 16.802139997482 seconds as plain vanilla PHP, and 3.9628620147705 as a PHP extension built using the tool.
As an added advantage the tool also provides an additional feature. The ability to combine PHP code (to be converted to C) and native C code within the same extension which can produce even greater performance enhancements. The same example used above only tool 0.14397192001343 seconds when much of the intensive code was moved to a bubble sort C code and simply calling it from within the PHP code.
As a side note functionally to the end developers using the code using the extension is very much similar to having the files manually included in the PHP file being developed except it doesn't have to be specifically included as it is done through the PHP extensions component.
(Disclaimer: I am not affiliated with this developer but am glad to have come across it as it is thus far working for converting some of my intensive classes into PHP extensions without needing to know C).

Move to php in windows? Concern, hints, "please don't do!"?

I am considering to move frome Microsoft languages to PHP (just for web dev) which has quite an interesting syntax, a perlish look (but a wider programmer base) and it allows me to reuse the web without reinventing it. I have some concerns too. I would be more than happy to gather some wisdom from stackoverflow community, (challenge to my opinions warmly welcome). Here are my doubts about using PHP on IIS web server on windows server .
Efficiency. Cgi are slow, what I am supposed to use? Fastcgi? Or what else?
Efficiency + stability. Is PHP on windows really stable and a good choice in terms of performances?
Database. I use very often MSSQL (I regret, i like it). Could I widely and efficiently interface PHP with MSSQL (using smartly stored pro, for example).
XSLT + XML performance. I work quite a lot with XML and XSLT and I really find the MS xml parser a great software component. Are parser used in PHP fast, reliable and efficient (I am interested mainly in DOM, not SAX)?
Objects. Is the PHP object programming model valid end efficient?
6 Regex. How efficient is PHP processing regexp?
Many thanks for your advices.
Efficiency. Cgi are slow, what I am supposed to use? Fastcgi? Or what else?
PHP runs as Apache module so there is no need for FastCGI.
Efficiency + stability. Is PHP on windows really stable and a good choice in terms of performances?
Personally i wouldn't use PHP on Windows but my experience shows that there is no big difference to Linux & PHP
Database. I use very often MSSQL (I regret, i like it). Could I widely and efficiently interface PHP with MSSQL (using smartly stored pro, for example).
PHP can access MSSQL via ODBC or via the native MSSQL extension. You might want to look into PostgreSQL though.
XSLT + XML performance. I work quite a lot with XML and XSLT and I really find the MS xml parser a great software component. Are parser used in PHP fast, reliable and efficient (I am interested mainly in DOM, not SAX)?
No experience there, sorry.
Objects. Is the PHP object programming model valid end efficient?
Since PHP 5 (especially 5.3) Object oriented programming in PHP is acceptable. It supports everything most other languages support, inheritance, interfaces, overloading, ...
Regex. How efficient is PHP processing regexp?
PHP uses the PCRE library afair so there shouldn't be much difference to other languages.
All in all:
I'm no fan of PHP, i greatly prefer languages with strong types like C/C++/C#/Java but for a scripting language PHP made huge improvements to the PHP we knew a few years ago. If you stick to object oriented programming PHP can be a clean and good language. The main drawback is:
PHP has no object oriented base, i.e. no string class, it uses C-like functions (strchr, strstr, strlen, ...), this makes OOP harder, you have to have more discipline to develop good code.
You should also consider cost. PHP + MySQL doesn't cost big money like building on top of a Microsoft stack (Asp.net + SQL Server + Windows Server). Hello licensing fees!
If you are doing PHP and considering MySQL you might as well be on a LAMP stack.
That depends on which web server you are using (or want to use). In Apache you can embed PHP as a module, which is faster than CGI. I'm not sure whether this can be done with IIS too.
I have been using PHP on Windows for about 6 years now, it has never crashed; of course there are the usual infinite loops, but restarting the web server is always sufficient. Also, the efficiency and stability are more related to the web server than to the operating system.
Yes, see: http://nl2.php.net/mssql
For DOM there is: http://php.net/manual/en/book.dom.php I don't know how it compares in performance with other XML parsers, I mainly use the SimpleXML http://nl3.php.net/simplexml parser. XSLT is a bit outdated in PHP, it only supports version 1.0: http://nl2.php.net/manual/en/book.xslt.php
PHP has a good Object Oriented programming model; it supports classes, interfaces, statics, exceptions, reflection, etc. But as it is a scripting language it lacks strong typing.
See: http://nl3.php.net/manual/en/ref.pcre.php
In answer to question 3 - yes, you can easily connect to mssql dbs using PHP. Read more in the PHP manual - http://php.net/manual/en/ref.mssql.php or use an abstraction layer like Pear::MDB2 - http://pear.php.net/manual/en/package.database.mdb2.intro.php

Categories