PHP Community

ServerGrove Blog: Symfony2 components overview: Translation

PHPDeveloper.org - Tue, 18/03/2014 - 23:37

The ServerGrove blog has posted their latest up-close look at the various components that make up the Symfony2 framework. In their latest post, they focus in on the Translator component.

Modern applications need to be internationalized and localized to be able to reach people from all over the world. Internationalization - aka i18n - is the process of designing a software application so that it can be adapted to various languages and regions without engineering changes. Localization - aka l10n - is the process of adapting internationalized software for a specific region or language by adding locale-specific components such as dates or currency. The Translation component provides different tools to get your application internationalized, but not localized.

The post covers the three main parts of the component - Catalogues, Loaders and Dumpers - and includes a simple example of creating the object, adding resources and calling "trans" to translate. There's also an example of using the YAML file loader to include the translated strings. There's also mentions of pluralization, translation "domains" and custom loaders.

Link: http://blog.servergrove.com/2014/03/18/symfony2-components-overview-translation/

Community News: Packagist Latest Releases for 03.18.2014

PHPDeveloper.org - Tue, 18/03/2014 - 15:01
Recent releases from the Packagist:

Community News: Latest PECL Releases for 03.18.2014

PHPDeveloper.org - Tue, 18/03/2014 - 14:04
Latest PECL Releases:
  • pthreads 2.0.1 Add globals inheritance option Add method to execute block in global scope Fix build when SPL is not loaded (spl sucks)

  • qb 2.1.1 Initial release

  • gmagick 1.1.7RC2 Changes to update support for PHP 5.6.0beta

  • solr 1.1.0b - SolrClient::system Access system servlet which fetch Solr Server System Information - SolrClient::commit argument $maxSegments is now DEPRECATED - SolrClient::commit Added support for expungeDeletes on - All SolrClient methods throws SolrClientExceptions instead of E_WARNING + SolrClientException - SolrClientExceptions' messages are more informative in case of connection errors - Added json extension validation - All SolrResponse, SolrQueryResponse, SolrUpdateResponse, SolrPingResponse, SolrGenericResponse, SolrDocument, and SolrInputDocument classes are now final - All parameters functions throws SolrIllegalArgumentException instead of E_RROR - SolrParams/SolrModifiableParams/SolrQuery throws SolrIllegalArguments Exception instead of E_ERROR (Feature #66858) - Various Bug Fixes

  • pthreads 2.0.2 Fix build in BSD and other *nix where PTHREAD_MUTEX_RECURSIVE_NP is enum

  • eio 1.2.4 Fix: Bitbucket issue #1: eio_open fails when file is owned by root

  • pthreads 2.0.0 Fix errors; inheritance and scope in threads (bugs in prepare) Fix fault; accessing destroyed objects (throw ex) Make use of inheritance within pthreads (bc compatible using alias) Remove abstract flag from ::run method Remove use of errors in favour of exceptions Remove all final modifiers on threaded objects Fix fault; submit to incorrectly constructed Pool Fixed fault; (re)using primitives that are object members across contexts Fixed fault; intermittent fault on session_start inside threads Various internal improvements

  • memcached 2.2.0RC1 - Fixes incorrect size when compressing serialized objects - Fixes endianess of compressed values

  • oci8 2.0.8 Enhancement - Improve performance of multi-row OCI_RETURN_LOB queries (Bug #66875)

  • mongo 1.5.0RC1 ** Bug * [PHP-995] - JSON detection * [PHP-996] - Broken with cyrus-sals 2.1.23 * [PHP-999] - Inline mapReduce command ignores read preferences * [PHP-1000] - RP support for "mapReduce" command, not just "mapreduce" ** Improvement * [PHP-998] - Include maxWriteBatchSize and maxMessageSizeBytes in connection info ** Task * [PHP-407] - MongoBinData should default to type 0 instead of 2 * [PHP-960] - Use createIndexes command when available * [PHP-987] - Use maxWriteBatchSize from ismaster for write command batch splitting. ** Sub-task * [PHP-993] - Merge batch return values into one return value

Oracle Announces Call for Proposals for MySQL Connect @ OpenWorld 2014

MySQL.com - Tue, 18/03/2014 - 02:59
Oracle’s MySQL Engineers, Customers, Partners and Community Members Come Together to Share Best Practices during Oracle OpenWorld in San Francisco
Categories: PHP Community

Symfony in Drupal 8

Planet-PHP - Mon, 17/03/2014 - 18:00

If you are a Drupaler, you must be aware that Drupal 8 is on the way. What you may not know is that it includes a few important Symfony components. Working with Drupal 8.x will give Drupalers an opportunity to become a part of a massive learning curve and is going to tempt them to know more about Symfony. In this article, we discuss the Symfony components that have been added to Drupal 8, covering some third party libraries along the way.

Before we get into the actual article, let us first briefly cover Symfony. It is a PHP based web application framework that follows the MVC architecture. Moreover, it is an open source project that has been released under the MIT license. Please make sure you don’t get it confused with Symfony CMS. If you wish to explore the Symfony framework into greater detail, see its Wiki page or any of the previous SitePoint articles about it.

Continue reading %Symfony in Drupal 8%

Categories: Open Source, PHP Community

PHP 5.6 and the Splat Operator

Planet-PHP - Mon, 17/03/2014 - 10:44

We have a couple of new features coming in to PHP 5.6 with names that sound much less exciting than the features they actually represent: "variadic functions" sound positively academic, and "argument unpacking" isn't exactly catchy. However they both use a new operator in PHP which looks like an elipsis (three dots ...) and is referred to as either the splat operator or the scatter operator. I included them in a recent version of my "Upgrading PHP" talk so I thought I'd share the examples here too in case anyone is interested.

Variadic Functions

This feature allows you to capture a variable number of arguments to a function, combined with "normal" arguments passed in if you like. It's easiest to see with an example:

    function concatenate($transform, ...$strings) {
        $string = '';
        foreach($strings as $piece) {
            $string .= $piece;
        }
        return($transform($string));
    }

    echo concatenate("strtoupper", "I'd ", "like ",
        4 + 2, " apples");

The parameters list in the function declaration has the ... operator in it, and it basically means " ... and everything else should go into $strings". You can pass 2 or more arguments into this function and the second and subsequent ones will be added to the $strings array, ready to be used.

Argument Unpacking

This has a less sexy name than variadic functions, and it uses the same operator, but this is the one that made me describe PHP code as "wild" - not something that happens often! I like it because it gives a different way of using functions that already exist so it becomes relevant as soon as you upgrade to 5.6.

Variadic functions allow you to declare an array of incoming parameters, and argument unpacking allows you to pass an array in to a function expecting separate parameters in the traditional way; they are absolutely complementary to one another. To use this feature, just warn PHP that it needs to unpack the array into variables using the ... operator. A simple example could look like this:

    $email[] = "Hi there";
    $email[] = "Thanks for registering, hope you like it";

    mail("someone@example.com", ...$email);

You can pass all of your arguments in as an array (pro tip: associative arrays won't work here), or just the last however many you like, and PHP will take your array and pass each element in as the next parameter in turn. I think this is pretty neat :)

PHP 5.6 Is Coming

PHP 5.6 isn't released yet, it'll be out probably sometime this summer. While it's feature list isn't huge, that means the upgrade pain shouldn't be huge either - and neat additions like the two features I've picked out here are very welcome additions in my book. PHP gets better with every release and I tip my hat to all those involved - thank you all!

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

Categories: Open Source, PHP Community

PHP 5.6 and the Splat Operator

Planet-PHP - Mon, 17/03/2014 - 10:44

We have a couple of new features coming in to PHP 5.6 with names that sound much less exciting than the features they actually represent: "variadic functions" sound positively academic, and "argument unpacking" isn't exactly catchy. However they both use a new operator in PHP which looks like an elipsis (three dots ...) and is referred to as either the splat operator or the scatter operator. I included them in a recent version of my "Upgrading PHP" talk so I thought I'd share the examples here too in case anyone is interested.

Variadic Functions

This feature allows you to capture a variable number of arguments to a function, combined with "normal" arguments passed in if you like. It's easiest to see with an example:

    function concatenate($transform, ...$strings) {
        $string = '';
        foreach($strings as $piece) {
            $string .= $piece;
        }
        return($transform($string));
    }

    echo concatenate("strtoupper", "I'd ", "like ",
        4 + 2, " apples");

The parameters list in the function declaration has the ... operator in it, and it basically means " ... and everything else should go into $strings". You can pass 2 or more arguments into this function and the second and subsequent ones will be added to the $strings array, ready to be used.

Argument Unpacking

This has a less sexy name than variadic functions, and it uses the same operator, but this is the one that made me describe PHP code as "wild" - not something that happens often! I like it because it gives a different way of using functions that already exist so it becomes relevant as soon as you upgrade to 5.6.

Variadic functions allow you to declare an array of incoming parameters, and argument unpacking allows you to pass an array in to a function expecting separate parameters in the traditional way; they are absolutely complementary to one another. To use this feature, just warn PHP that it needs to unpack the array into variables using the ... operator. A simple example could look like this:

    $email[] = "Hi there";
    $email[] = "Thanks for registering, hope you like it";

    mail("someone@example.com", ...$email);

You can pass all of your arguments in as an array (pro tip: associative arrays won't work here), or just the last however many you like, and PHP will take your array and pass each element in as the next parameter in turn. I think this is pretty neat :)

PHP 5.6 Is Coming

PHP 5.6 isn't released yet, it'll be out probably sometime this summer. While it's feature list isn't huge, that means the upgrade pain shouldn't be huge either - and neat additions like the two features I've picked out here are very welcome additions in my book. PHP gets better with every release and I tip my hat to all those involved - thank you all!

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

Categories: Open Source, PHP Community

GoogleAppEngine 1.9.0. – PHP Updates

Planet-PHP - Sat, 15/03/2014 - 20:44

It’s been a while since I published my Getting Started with PHP on GAE Article, and the platform has been doing better than anyone had expected. The PHP feature request is still at the top of the NFR list, and the Phalcon NFR I created way back then is now sitting at top 17, indicating […]

Continue reading %GoogleAppEngine 1.9.0. – PHP Updates%

Categories: Open Source, PHP Community

Community News: Packagist Latest Releases for 03.15.2014

PHPDeveloper.org - Sat, 15/03/2014 - 15:07
Recent releases from the Packagist:

Performance improvement for OCI_RETURN_LOBS in PHP OCI8 2.0.8

Planet-PHP - Sat, 15/03/2014 - 00:48

Reducing "round trips" to the database server is important for performance and ultimately for system scalability. A server round-trip is defined as the trip from PHP to the database server and back to PHP.

Reducing round trips makes everything more efficient: PHP is faster, there is less network overhead, the database doesn't have to do a context switch or do any processing for you. Applications have some control over round trips, for example by effectively using prefetching or by using an appropriate execute mode to minimize unneccessary rollbacks at the end of a script.

The bug filer of Bug 66875 noticed that PHP OCI8's implementation itself could reduce round trips if a particular LOB column meta data value was cached for the duration of a query instead of being re-requested for each row of the query result set.

So, now with OCI8 2.0.8, you should see a performance increase if you are doing multi-row queries involving LOB columns returned as OCI_RETURN_LOBS:

$s = oci_parse($c, "select mylobcol from mylobtab");
oci_execute($s);
while (($row = oci_fetch_array($s, OCI_ASSOC+OCI_RETURN_LOBS)) !== false) {
    echo $row['MYLOBCOL'], "\n";
}

The bug filer tested the patch and added his performance improvement benchmark results to the bug report. The benefit in your environment will vary greatly with the network setup, schema, and how many LOB columns are queried. Test it out and let me know how the new version helps you.

There is no immediate change for LOBs fetched with OCI-Lob::read() and OCI-Lob::load(). This would require a more complex patch than I want to apply at this time. Queries that don't use LOBs are not affected in any way by the patch.

OCI8 2.0 is included in the forthcoming PHP 5.6 code base. For PHP 5.2 to PHP 5.5 you can install it from PECL. PHP 5.5 RPMs with PHP OCI8 2.0.8 are available from oss.oracle.com.

Finally, if your LOB queries return multiple rows, you might also like this tip to reduce PHP memory usage.

Categories: Open Source, PHP Community

Community News: Three Devs and a Maybe Podcast

PHPDeveloper.org - Fri, 14/03/2014 - 19:51

The Three Devs and a Maybe podcast has been around since the end of last year and has posted some great episodes on a wide variety of topics, including several shows related to PHP. Some of their current shows include:

Check out the podcast and the past episodes and be sure to subscribe to their feed if you enjoy the show!

Link: http://threedevsandamaybe.com

Jonathan Hill: How much does it cost to be a web developer?

PHPDeveloper.org - Fri, 14/03/2014 - 18:17

Jonathan Hill has taken an interesting perspective in his recent post looking more at some of the average financial costs around being a web developer.

With Software Development topping 2014′s top jobs list, I thought I would share how much it cost me to become a web developer, and what my monthly expenses look like nowadays.

He breaks it down into a few different categories, listing an average price for each:

  • Initial (start-up) costs for hardware and software
  • Training costs
  • Recurring costs

Obviously, not all of the software and tools he lists are needed for every software developer, but it does give some perspective. Thankfully, he also links to some free alternatives to the tools he mentions that can reduce these costs as well.

Link: http://jonathonhill.net/2014-02-19/how-much-does-it-cost-to-be-a-web-developer/

Building a Twitter Hashtag Contest – Registering the App

Planet-PHP - Fri, 14/03/2014 - 18:00

This entry is part 1 of 2 in the series Building a Twitter Hashtag Contest with Twitter's APIIntroduction Social networking sites play a vital role in increasing the popularity of a website or application. The vast majority of web sites provide the ability to share their content on popular social media sites with the click […]

Continue reading %Building a Twitter Hashtag Contest – Registering the App%

Categories: Open Source, PHP Community

ServerGrove Blog: Symfony2 components overview: Templating

PHPDeveloper.org - Fri, 14/03/2014 - 17:11

The folks at ServerGrove have posted the latest in their series focusing in on various components of the Symfony2 framework. This time they look at the Templating component, useful for working with the output from the application, web or otherwise.

The Templating component provides an engine-agnostic infrastructure to load template files and render them using the input variables. Although the component provides methods for creating template systems, we are going to focus on how to integrate third-party template engines like Twig and Smarty, and how to use the right engine based on the templates file extension.

The post talks about typical PHP output (with escaping) and shows the difference between a call with htmlspecialchars and the use of the Template component to render a view. An example is also included showing the use of other template engines into the template object, plugged directly into the "render" method. The end of the post also briefly mentions an alternative template language, Plates, an option similar to Twig but uses native PHP rather than tags and placeholders.

Link: http://blog.servergrove.com/2014/03/11/symfony2-components-overview-templating/

SitePoint PHP Blog: Building a Simple Blog App with MongoDB and PHP

PHPDeveloper.org - Fri, 14/03/2014 - 16:19

On PHPMaster.com there's a recent tutorial posted showing you the creation of a simple blog application with MongoDB + PHP. It's a basic overview, so it's mostly about creates and reads, but it does help get things working.

If you want to create a blog using MongoDB and PHP, this article will teach you. [...] The reason I chose to build a blog application is because it is a basic CRUD application and it is very suitable for easing into PHP and MongoDB web development. We will build a plain user interface using Bootstrap with simple textboxes and buttons. A MongoDB database will store all the content.

He starts off by introducing MongoDB and some of the basic concepts around databases, collections and documents as they relate to it. He then moves into the installation process, getting and configuring a simple MongoDB instance running on localhost. He helps you get the MongoDB PECL driver installed for PHP and includes a bit of code to test the connection. Finally, he gets into the blog example itself and includes the full code to get it up and running.

Link: http://www.sitepoint.com/building-simple-blog-app-mongodb-php/

Community News: Packagist Latest Releases for 03.14.2014

PHPDeveloper.org - Fri, 14/03/2014 - 15:00
Recent releases from the Packagist:

Methods on primitive types in PHP

Planet-PHP - Fri, 14/03/2014 - 09:00

A few days ago Anthony Ferrara wrote down some thoughts on the future of PHP. I concur with most of his opinions, but not all of them. In this post I’ll focus on one particular aspect: Turning primitive types like strings or arrays into “pseudo-objects” by allowing to perform method calls on them.

Lets start off with a few examples of what this entails:

$str = "test foo bar";
$str->length();      // == strlen($str)        == 12
$str->indexOf("foo") // == strpos($str, "foo") == 5
$str->split(" ")     // == explode(" ", $str)  == ["test", "foo", "bar"]
$str->slice(4, 3)    // == substr($str, 4, 3)  == "foo"

$array = ["test", "foo", "bar"];
$array->length()       // == count($array)             == 3
$array->join(" ")      // == implode(" ", $array)      == "test foo bar"
$array->slice(1, 2)    // == array_slice($array, 1, 2) == ["foo", "bar"]
$array->flip()         // == array_flip($array)        == ["test" => 0, "foo" => 1, "bar" => 2]

Here $str is just a normal string and $array just a normal array - they aren’t objects. We just give them a bit of object-like behavior by allowing to call methods on them.

Note that this isn’t far off dreaming, but something that already exists right now. The scalar objects PHP extension allows you to define methods for the primitive PHP types.

The introduction of method-call support for primitive types comes with a number of advantages that I’ll outline in the following:

An opportunity for a cleaner API

The likely most common complaint you get to hear about PHP is the inconsistent and unclear naming of functions in the standard library, as well as the equally inconsistent and unclear order of parameters. Some typical examples:

// different naming conventions
strpos
str_replace

// totally unclear names
strcspn                  // STRing Complement SPaN
strpbrk                  // STRing Pointer BReaK

// inverted parameter order
strpos($haystack, $needle)
array_search($needle, $haystack)

While this issue is often overemphasized (we do have IDEs), it is hard to deny that the situation is rather suboptimal. It should also be noted that many functions exhibit problems that go beyond having a weird name. Often edge-case behaviors were not properly considered, thus creating the need to specially handle them in th

Truncated by Planet PHP, read more at the original (another 22929 bytes)

Categories: Open Source, PHP Community

PHPClasses.org: Lately in PHP Podcast #45 - "The Security of Future PHP Versions"

PHPDeveloper.org - Thu, 13/03/2014 - 20:17

The latest episode of the "Lately in PHP" podcast series has been released by PHPClasses.org today - Episode 45, "The Security of Future PHP Versions".

As the plans for the upcoming PHP 5.6 and PHP 6 versions are being finalized, some of the proposals are about improving the security of these future PHP versions. That has been one of the main topics discussed by Manuel Lemos and César Rodas on the episode 45 of the Lately in PHP podcast. They also have talked about several other types of proposals and ideas for PHP 6, as well a tutorial on How to Use a Webcam to take Pictures in PHP Application.

You can listen to this latest episode in a few ways - either through the in-page audio player, by downloading the mp3 or you can watch the live recording over on YouTube.

Link: http://www.phpclasses.org/blog/post/229-The-Security-of-Future-PHP-Versions--Lately-in-PHP-podcast-episode-45.html

Ulf Wendel: The performance penalty of the early MySQL Fabric support for PHP

PHPDeveloper.org - Thu, 13/03/2014 - 19:16

In his latest post Ulf Wendel looks at the performance issues around the recently introduced MySQL Fabric support included in the mysqlnd extension.

PECL/mysqlnd_ms 1.6 is currently being modified to support sharding and fully automatic server and client failover when using MySQL Fabric (slides) to manage a farm of MySQL servers. PECL/mysqlnd_ms is a mostly transparent load balancer that works with all PHP MySQL APIs (PDO_MySQL, mysqli, ...). The idea is, that if, for example, a MySQL server fails, the plugin talks to MySQL Fabric to learn about alternative servers that Fabric has provisioned automatically. This "talks to" gives implies a performance penalty for applications.

He takes a look at what's happening "behind the scenes" when it comes to using the Fabric functionality and sharding (based on the use of mysqlnd_ms_select_shard). He traces through the execution path and how much slower then end result is. He includes some results from the connection debugging and the number of queries a single request makes.

Link: http://blog.ulf-wendel.de/2014/the-performance-penalty-of-the-early-mysql-fabric-support-for-php/
Syndicate content