Remi ColletApache httpd server 2.4.10 and PHP-FPM 5.6 in Fedora 21 (1.8.2014, 18:04 UTC)

Since the update in Fedora 21 of httpd version 2.4.10 and php 5.6.0RC3, you can avoid using mod_php. php-fpm works "out of the box", with default provided configuration.

Installation:

# yum remove php
# yum install php-fpm httpd

Services:

# systemctl start php-fpm.service
# systemctl start httpd.service

Test

# echo '<?php phpinfo()' >/var/www/html/info.php

URL: http://localhost/info.php

You should see the message :  Server API: FPM/FastCGI

Configuration

The default provided configuration now work in Fedora 21.

You can use the same in Fedora 19 and 20, applying some change to your PHP configuration file  /etc/httpd/conf.d/php.conf

Disable the php_* directives, when mod_php is not loaded:

# mod_php options
<IfModule mod_php5.c>
...
php_value session.save_handler "files"
php_value session.save_path "/var/lib/php/session"
php_value soap.wsdl_cache_dir "/var/lib/php/wsdlcache"
</IfModule>

Enable redirect the execution of php scripts to php-fpm service:

# Redirect to local php-fpm if mod_php is not available
<IfModule !mod_php5.c>
<FilesMatch \.php$>
SetHandler "proxy:fcgi://127.0.0.1:9000"
</FilesMatch>
</IfModule>

Apache httpd server optimisation

Time to leave the prefork MPM in /etc/httpd/conf.modules.d/00-mpm.conf

LoadModule mpm_event_module modules/mod_mpm_event.so

For packagers

php-fpm only pull httpd-filesystem, for user creation and configuration directory ownership and can still be used without httpd, for example with  nginx. Despite I still think than Apache httpd server still the best server to package web applications, mostly as it allows to drop a configuration file, per application, with global alias.

I encourage you to test your applications with this configuration, especially to ensure than all php_* directives are properly conditionalized..

Next step will be to drop the dependency on mod_php and give back the choice to our users.

Conclusion

This feature finally drop the difficulty to use PHP-FPM and other Apache MPM. A pity that it is not available in httpd version provided by RHEL/CentOS-7.

Link
Bruno ŠkvorcFixed Point Math in PHP with BCMath, precision loss cases (1.8.2014, 18:00 UTC)

When dealing with fixed point numbers, you have to be very careful - especially if you develop with PHP and MySQL. In this article, obstacles and subtleties of working with the PHP BCMath extension, MySQL fixed point expression handling and persisting fixed point data from PHP to MySQL are described. Despite the occurring barriers we try to figure out how to work with fixed point numbers and not to lose a digit.

Troubles with BCMath

BCMath documentation says:

For arbitrary precision mathematics PHP offers the Binary Calculator which supports numbers of any size and precision, represented as strings.

So BCMath function parameters should be represented as strings. Passing numeric values to bcmath can lead to wrong results, the same precision loss as when we treat double value as string

Case 1

echo bcmul(776.210000, '100', 10) . PHP_EOL;
echo bcmul(776.211000, '100', 10) . PHP_EOL;
echo bcmul(776.210100, '100', 10) . PHP_EOL;

echo bcmul(50018850776.210000, '100', 10) . PHP_EOL;
echo bcmul(50018850776.211000, '100', 10) . PHP_EOL;
echo bcmul(50018850776.210100, '100', 10) . PHP_EOL;

Results are:

77621.00
77621.100
77621.0100
5001885077621.00
5001885077621.100
5001885077621.00 //here we can see precision loss

Never pass numeric values to BCMath functions, only string values that represent numbers. Even when not dealing with floating points, BCMath can output strange results:

Continue reading %Fixed Point Math in PHP with BCMath, precision loss cases%

Link
blog.phpdeveloper.orgPHP, PDO & HP Vertica (1.8.2014, 15:39 UTC)

As part of my new role, we’ll be working with HP’s Vertica for some of the data storage. I’ve been struggling the last few days to get it working on a Vagrant-provisioned linux box (VirtualBox) and finally have the process down. I thought I’d share it for those out there needing some help. I’m working with a Ubuntu server box, but these instructions could be pretty easily adapted to other distros:

1. Ensure you have the Unix ODBC package installed. This is what PDO uses to connect to the Vertica instance:

sudo apt-get -y install unixodbc

2. Ensure that your PHP installation has PDO support with ODBC handling:

php -m | grep -i odbc

You should see something like “PDO_ODBC” there if it’s installed.

3. Grab the latest Vertica linux drivers from the My.Vertica site (requires a login). Click on the Downloads section and scroll all the way down to the drivers. Grab the right ones for your linux installation. I used the Linux ODBC 64-bit.

4. Make a “/opt/vertica” directory on your system and untar the archive there.

sudo mkdir /opt/vertica
sudo tar zxvf vertica-odbc-6.1.3-0.x86_64.linux.tar.gz -C /opt/vertica/ > /dev/null

5. Create the configuration files where needed. There’s three of them – odbc.ini, odbcinst.ini and vertica.ini. Here’s the examples and the paths for them:

In /etc/odbc.ini:

[VerticaDev]
Description = Vertica Dev
Driver = /opt/vertica/lib64/libverticaodbc.so
Port = 5433
ServerName = your-hostname-here.com
DatabaseName = database-name
UserId = database-username
Driver = Vertica

In /etc/odbcinst.ini:

[Vertica]
Description = Vertica driver
Driver = /opt/vertica/lib64/libverticaodbc.so

In /etc/vertica.ini:

[Driver]
DriverManagerEncoding=UTF-16
ODBCInstLib = /usr/lib/x86_64-linux-gnu/libodbcinst.so.1
ErrorMessagesPath=/opt/vertica/lib64
LogLevel=4
LogPath=/tmp

If all goes well, you should be able to make a script like this to test it:

<?php
$dbName = 'your-database-name';
$hostname = 'your-hostname.com;
$account = 'your-username';
$password = 'your-password';
$driver = 'Vertica';

$dsn = 'Driver='.$driver.';Server='.$hostname.';Database='.$dbName;
$pdo = new \PDO('odbc:'.$dsn, $account, $password);
var_export($pdo);
?>
Link
Thomas WeinertFluentDOM 5 (1.8.2014, 12:58 UTC)
FluentDOM 5.0.0 is now released.

Up to version 4.1, FluentDOM was an implementation of the jQuery Traversing and Manipulation APIs in PHP. Version 5 is a complete rewrite and adds a secondary focus. FluentDOM now provides extended variants of PHPs DOM classes, too. This allows workarounds for bugs, syntax sugar and shortcuts.

Bugs

#39521

The second argument to DOMDocument::createElement() it breaks if it contains an entity. FluentDOM avoids that by creating and appending a text node. Additionally it adds a third argument to provide attributes.

#55700

By default PHP registers the namespace definitions of the current context. This uses the namespace prefixes as identifiers, but they are not. They are allowed to change (even on different elements in the same document). You should always register your own prefixes so you do not depend on the prefixes in the document - they are just not relevant. So the automatic registration costs performance without a real gain in the best case. In the worst case it overrides a your namespace registration and you can not fetch the data you want.

FluentDOM adds a property to change this behavior. The automatic namespace registration is disabled by default and can be activated using the property or the third argument for evaluate()/query().

Syntax Sugar

Cast To String


Most of the nodes can be cast to string. for example the following will return the whole text content of an document.

echo $dom->documentElement;

Iterator For Child Nodes


FluentDOM\Element is iterate-able. Using foreach() on it will iterate over the child nodes. The Iterator is a RecursiveIterator, too.

ArrayAccess

FluentDOM\Element allows array syntax. A numeric key like $element[1] will access the child node. An qualified name string like $element['href'] will access the attribute.

Namespaces

FluentDOM\Document allows to register namespaces on the document. If methods like setAttribute() or createElement() recognize a colon in the tag name, they will resolve the namespace prefix an call their namespace aware variant.

Shortcuts

FluentDOM\Document::createElement() allows to provided content and attributes. FluentDOM\Element::appendElement() allows to create and append an element with a single call.

Other methods of the FluentDOM\Element class are variants of the document variants using the element node as default context. 

Backwards Compatbility

FluentDOM 5 is mostly backwards compatible. The FluentDOM() function still exists and the returned FluentDOM\Query instance has the same jQuery like API. Only the loaders where changed.

CSS Selectors

The FluentDOM\Query class allows to set an callback function that is used to convert the provided selectors to xpath expressions. FluentDOM::QueryCss() returns a FluentDOM\Query instance that supports CSS selectors. You will need to have Carica PhpCss or Symfony CSS-Selector installed in you project.



Link
Christopher JonesNew Oracle Technology Network PHP Forum URL (31.7.2014, 18:29 UTC)
The Oracle Technology Network (which promotes the development community) is upgrading its software platform and reorganizing some content. The PHP Oracle forum is now at https://community.oracle.com/community/development_tools/php. The top level "PHP Developer Center" is at http://www.oracle.com/technetwork/database/database-technologies/php/whatsnew/index.html. I notice my old bookmarks for the Developer Center redirect to its current location, but this doesn't seem true of some very old URLs for the forum.
Link
Bruno ŠkvorcIntroducing InvoiceNinja: Self-hosted Invoicing (31.7.2014, 16:00 UTC)

For a freelancer, nothing is more important than time. Tracking invoices or doing paperwork can quickly become tedious and occupy a large portion of that. In March, I showed you FusionInvoice, a tool to keep track of your clients and invoices. Although it’s a nice and easy to use tool, its open-source version has since been discontinued and in part taken over by InvoicePlane. In this post, however, I’d like to introduce you to InvoiceNinja.

Introducing InvoiceNinja

InvoiceNinja is an open-source self-hosted and cloud hosted invoicing platform.

True to its motto, InvoiceNinja’s interface is simple and intuitive making creating invoices a breeze. Tasks like managing clients, issuing a new invoice or adding a payment are just simple actions that even an inexperienced user will feel comfortable doing. Its simplistic dashboard greets the user displaying relevant information about the invoices created and their status. The live preview of the invoice will help you to easily review it before sending it to your clients.

Through integration with PayPal, Google Wallet and 21 other payment processors, InvoiceNinja makes it very easy for your clients to reimburse you for your work directly through the application.

Continue reading %Introducing InvoiceNinja: Self-hosted Invoicing%

Link
PHP: Hypertext PreprocessorPHP 5.6.0RC3 is available (31.7.2014, 00:00 UTC)
The PHP development team announces the immediate availability of the third release candidate of PHP 5.6. As we entered the feature freeze with beta1, this is a bugfix-only release. All users of PHP are encouraged to test this version carefully, and report any bugs in the bug tracking system. THIS IS A DEVELOPMENT PREVIEW - DO NOT USE IT IN PRODUCTION! For more information about the new features you can check out the work-in-progress documentation or you can read the full list of changes in the NEWS file contained in the release archive. For source downloads of PHP 5.6.0RC3 please visit the download page. Windows binaries can be found on windows.php.net/qa/. Our next Release Candidate should show up on the 14th of August. Thank you for helping us make PHP better.
Link
Bruno Škvorc4 Features That Make Me Choose NuSphere PhpED (30.7.2014, 16:00 UTC)

In the last survey on the best PHP IDE for 2014, my longtime favorite PhpED was missing. I didn’t act on it then, but what better way to spread the love than to devote an article to it.

I’ve spent the first part of my programming career without a real IDE. UltraEdit was meeting most of my needs. At a certain point you start to realize you’re missing out on something and the quest for a real IDE begins.
For quite some time I was relatively happy with NetBeans; after some time though, I did find myself fighting it on too many occasions. I again concluded that it was time to move on. Having a historical hate for Eclipse (we had a serious misunderstanding back at version 3 dot something from which I still haven’t recovered) meant I had to test the commercial IDEs.

Why I chose PhpED

Speed, overview and simplicity. That sums it up, really. There are a few things that mattered for me, speed-wise; switching projects, getting code suggestions and fast debugging. Overview is something that I want because my projects get quite complex at times. An IDE like Eclipse overwhelms me with way too many options and buttons which I hardly ever use, keep it simple please. I believe I found my requirements and more in PhpED…

Project wizard

The project wizard will help you set up your project like you want it; simple local project, local server or remote server. Run on web server and/or CLI. Set up the directories, code page, PHP/HTML/CSS versions and finally checking to see if the debugger is working. It’ll be quite specific on how to fix issues or offer to fix them should there be any.

PhpED_project_wizzard.PNG

Coding

All the normal things are present when it comes to editing code: dynamic syntax highlighting for multiple languages, variable highlighting, fast searching and more. The code suggestion is instant; the IDE presents the possibilities that match the start that you typed. When you find what you wanted and your code is documented using PHPDoc, then it’ll show that while you’re entering your variables.

PhpED_code_insight.png

In the example above, you can perhaps spot something that can be improved; it fails to show multiline comments of the documentation. This is good to get a simple overview of the function call, but quite often you document something for a reason and you want to see it all.

Continue reading %4 Features That Make Me Choose NuSphere PhpED%

Link
Lorna MitchellNew PHP Videos on OReilly.com (30.7.2014, 07:50 UTC)

I am delighted to announce that I have new video titles available! I'm delighted for two reasons: selfishly, because these things take a lot of prep and I am pleased they are done; but also because I think it is very good news that a key industry player such as O'Reilly recognises PHP's place in the world and works hard to publish new content in this area.

There are two videos available: PHP Web Services and Intermediate PHP (subtitle: a bunch of things Lorna thinks will make developers' lives and applications better!), you can click through (disclaimer: affiliate links!) to get more information and a detailed chapter outline for each course. I hope that either or both of them will be useful to you.

Intermediate PHP

Intermediate PHPThis video is a bit of a combination of ideas; really it's aimed at PHP developers who have been leading sheltered lives for a few years, or who are just now moving beyond the beginner stage (we all start sometime, is my firm belief). The course includes useful demonstration of modern tools such as Composer, and also old ones that often get overlooked such as the commandline, security features, and PDO - all of which I've included with some real-world-ish examples.

New features in the last few versions of PHP have been very object-oriented. If you've never studied OOP formally, or if you're just moving up from function-based programming (hello, lovely Drupal devs!), then I think it's really important to get a good grounding. This course therefore includes a light intro to PHP so that you know where you are, before moving on to showing off the shiny new things that have been added more recently. For developers looking to brush up in any of these areas, I've tried to create real, practical examples and the code is all on github too.

PHP Web Services

PHP Web ServicesThis isn't quite the video of the book, because PHP Web Services is a textbook and the video is more of a "hey, look what we can make!". Also since the book has been out more than a year, there are a few things that have changed and the video is bang up to date with the newer tools. Again, lots of example code and it's all on github so you can pause the video to make me stop talking and have a prod around at it all yourself :) I'm of the opinion that APIs need not be rocket science; they are within reach of every developer once you know what to do and how to do it! This course does just that, I've tried to let you "look over my shoulder" as I build basic versions of the APIs and integration code I work with on a regular basis.

Whether you are a books person or a videos person depends mostly on your learning style. I love to teach in-person, and videos give an opportunity to *show* you rather than *tell* you how I would do a particular thing. Hopefully one or other of these videos are useful to you, please let me know how you get on!

(O'Reilly do run occasional promotions on their content and they notify me when it includes my stuff - I'll be retweeting from @lornajane if that happens!)

Lorna is an independent web development consultant, author and trainer, available for work (interesting projects only). This post was originally published at LornaJane

Link
Bruno ŠkvorcPHP News You May Have Missed – July 2014 (29.7.2014, 18:00 UTC)

A handful of news cropped up again that didn’t really get the attention they deserved, so I’ll use this opportunity to rehash some of them and explain others. The “news” here are usually less than brand new - instead, they’re bits of information you should pay attention to if you’re even the least bit interested in the PHP community and environment.

The Zend Rush

Zend, the company behind anything that has “Zend” in its name (Framework, Server, Studio, Engine…) has been very aggressive in product updates of late. They started the year off with a new release of their Zend Certification exam, continued with a huge update to the Zend Server, which we’ve covered in another post, and wrapped things up by updating Zend Studio to a new major version - it now goes to 11! We’ll be taking a more in-depth look at it in another post.

Continue reading %PHP News You May Have Missed – July 2014%

Link
LinksRSS 0.92   RDF 1.
Atom Feed   100% Popoon
PHP5 powered   PEAR
ButtonsPlanet PHP   Planet PHP
Planet PHP