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/
Related
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.
I've been reading about Facebook's Hack which lead me to reading about HipHop Virtual Machine. I wanted a better understanding of this and could not find a clear definition. Wikipedia defines it as: HipHop for PHP (shortened as HipHop) describes a series of PHP execution engines and improvements created by Facebook. I don't understand what PHP engines are...
So I guess then my question is: What exactly are "PHP execution engines?" and how exactly do the benefit PHP applications?
Thanks!
You can run your PHP code with the standard (Zend) engine that you download from php.net, that works great. If you download WAMP, MAMP, or any of the other pre-packaged PHP & MySQL for your Operating system packages, this is what you're getting.
Alternately you can run (most of[1]) your PHP code with HipHop, that works great.
Which one you're using should be effectively invisible to your end users. Your developers, and operations teams will need to know.
You may choose to use HipHop if you're running a site that gets a lot of traffic. HipHop while not supporting all of the features of PHP, does run a bunch faster. It also has some new features not available in the main PHP distribution mostly to do with type hinting. These can provide some pretty attractive tools to read through your code checking for bugs.
Reasons you may want to use HipHop:
Performance is a big deal for you
The static analysis tools available with HipHop have serious worth to your team
The new features in HipHop but not in Zend PHP are attractive to your team.
Reasons you may want to use Zend PHP
You need an extension not available for HipHop (there's lots of extensions out there, think: gd, curl, imagemagik, etc. Many are available for HipHop now, many aren't).
Your code, or framework is making use of unsupported features.
You have a lot of expertise in hosting your current Webserver & PHP stack, and don't want to start from scratch.
This post goes into some HHVM vs HACK differences, and gives a nice run down: http://www.marco.org/2014/03/21/hack
[1] Not all code that you can run with the regular PHP engine currently works on HipHop. They're working on most of the issues, some they've just decided not to fix (I think variable variables may be an example of this e.g. $$var)
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).
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/
I'm trying to accomplish a task and turns out that the code I need is packaged as a PHP extension, which according to what I've been told means I have to have root access to install it (I'm on shared hosting so that's a bit of a problem.
I'll solve this problem later, but for now I'm trying to understand the difference between an extension, a library, and a class. Is it more of a packaging thing that could be overridden and repackaged a different way, or is there a valid architectural reasoning behind it?
Also when releasing your own code, what makes you decide to release as library vs. class vs. extension? or do you go with whichever sounds better?
thanks in advance.
P.S. If you must know which extension I'm talking about, it's Libpuzzle, but that's really beside the point, my question is more general.
An extension is a pice of code programmed in C which will be included into the PHP core when PHP starts. Normally you have some more native functions available after including a extension. For example a zip functionality.
A class is a abstract pice of PHP code which solves common tasks. For example sending emails. You can find some common classes at pear.php.net.
A library is a collection of PHP classes wich solve more generic tasks for example buliding HTML forms AND sending emails. The Zend Framework is a framework which consists of many, many PHP classes.
Normally extension features can be programmed in PHP. For example the PEAR::Compat class. Often you will find the functionality you need as a PHP class available. I'm sure the stackoverflow readers will supply you with ideas where to find a specific PHP class.
Extensions are low-level. Usually written in C/C++, and compiled into native-code shared libraries, they interact with the Zend Engine directly. It has pros and cons, main advantages being the speed and more control; and main disadvantages - they are harder to install, and require compilation (and that requires a compiler and PHP headers); it's not true they require root access though - you only need ability to use custom php.ini (or dl() function, but I see they deprecated it for some reason).
Libraries/classes are high-level and interpreted. If you don't know if you need to write extension, then you probably don't. About what classes are - read about OOP. A library is a reusable collection of code (most commonly in form of functions/classes).
Some libraries (including libpuzzle) also include a command-line tool. So if you're unable to use the PHP library due to your shared hosting environment, maybe you can compile the command-line tool. Then you can run it from PHP using something like exec. It will be slower and require more memory than a library, but it might get the job done. Of course, many hosts also have restrictions on commands like exec, so this might not work either.