Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Kevin Schroeder:
Excluding Fields in the MongoDB/MongoDB Library
Mar 31, 2016 @ 16:18:05

In this new post to his site Kevin Schroeder has shared a helpful hint around the MongoDB library and excluding fields from the results of a query.

I am using the mongodb/mongodb library for a project of mine. The API seems fairly different from the old PECL library and it also came with some other, albeit unexpected, baggage. [...] One of the practices I’ve heard about Mongo is to get Mongo to do as much as it can, but not to worry too much about complicated joins and such as you would in SQL. In other words, don’t shy away from bringing data into the application to do some processing. That was the practice I followed, which worked fine up until my data size started to increase.

He started seeing some major performance issues when his data set grew to a significant size (50% of the response time). He went searching for a solution, tried MapReduce but eventually came upon an optional parameter letting him tell the Mongo DB to omit a value (or values) from the result set. Using this he dropped 7.5 seconds off of his wall clock time.

tagged: exclude fields result set mongodb library example parameter

Link: http://www.eschrade.com/page/excluding-fields-in-the-mongodbmongodb-library/

Michelangelo van Dam:
popen for cli commands and pipes in php
May 05, 2015 @ 15:53:38

Michelangelo van Dam has a quick new post to his site talking about popen and pipes in command-line PHP as an alternative to the "exec" functions PHP provides to make command lines calls.

I got a question today about using commands that pipe output to other commands within PHP applications. There are two functions in PHP that are perfect for the task: popen and proc_open. But when you want to run it as a complete process, you can go about using exec, shell_exec, passthru or system and fiddle with escapeshellcmd. But often this looks messy and not reusable. A better approach would be to use "popen".

He includes a code example of how to use this method, showing a call to a command line tool and piping the results back into a PHP variable for later use. You can find out more about the use of popen in the PHP manual and accompanying examples.

tagged: popen procopen commandline cli pipe result example

Link: http://www.dragonbe.com/2015/05/popen-for-cli-commands-and-pipes-in-php.html

Chris Jones:
Using PHP and Oracle Database 12c Implicit Result Sets
Jul 26, 2013 @ 14:12:40

Chris Jones has a new post to his site showing you how to use Oracle 12c's implicit result sets in your code. Note: this functionality is still in development, so the naming/exact functionality might change.

The new Oracle Database 12c "Implicit Result Sets" (IRS) feature allows query results to be returned from a stored PL/SQL procedure (or a PL/SQL anonymous block) without requiring special PHP code. Support for IRS is available in PHP OCI8 2.0.0-devel extension when it is compiled and used with Oracle Database 12c. (OCI8 2.0 can be compiled and used with other versions of Oracle Database but the available feature set is reduced).

He shows a normal fetch loop that calls the oci_* functions and grabs each row with a oci_fetch_row call. He updates this to use an anonymous PL/SQL block (a string) instead that allows for more flexibility. He includes examples that fetch from one table, multiple tables and returns multiple result sets (that can be fetched one at a time) from the same single call.

tagged: implicit result set oracle 12c tutorial multiple single sql plsql

Link: https://blogs.oracle.com/opal/entry/using_php_oci8_2_0

Johannes Schluter's Blog:
mysqlnd plugins and json
Sep 14, 2011 @ 16:04:48

Johannes Schluter has shared a handy mysqlnd plugin that he's written up that does two common things at once when you're pulling data from your database and pushing it into JSON - a mysqlnd_query_to_json function.

In my spare time I'm currently writing a shiny Web 2.0 application where I'm heavily using AJAX-like things, so what I do quite often in this application is, basically this: Check some pre-conditions (permissions etc.) then select some data from the database, do a fetch_all to get the complete result set as an array and run it through json_encode; Of course that example is simplified as I'm using the Symfony 2 framework for this project. [...] So I wrote a mysqlnd plugin.

His plugin (that he admits is "a hack") gives you the mysqlnd_query_to_json function that automagically transforms the results from the passed in query into JSON output. He notes some things lacking - like Unicode encoding and no MySQL bitfield support.

tagged: mysqlnd json plugin convert result

Link:

SitePoint PHP Blog:
Sophisticated Object Iterators in PHP
May 05, 2011 @ 17:54:59

Following up on their earlier simple object iterators post, the SitePoint PHP blog is back with a look at more sophisticated iterators you can use to work with database record objects.

In my previous post, Simple Object Iterators in PHP, we discovered how to iterate over array items defined within an object using a foreach loop. However, what if you need to iterate over items which are not stored in an array, e.g. records from a database or lines of text read from a file?

He shows how to create a script that pulls in the users from a database object (PDO, in this case) and implements the Countable and Iterator interfaces. These interfaces give it some special methods that can give counts of the results and help you iterate through the results - current, rewind, next and valid.

tagged: object iterator spl database result pdo countable implement

Link:

Chris Jones' Blog:
More on PHP and Oracle 11gR2 Improvements to Client Result Caching
Mar 04, 2011 @ 15:56:33

Chris Jones has posted more information to his Oracle blog about the caching and other improvements that come along with the Oracle 11gR2 release that can be used in PHP applications.

Oracle 11.2 brought several improvements to Client Result Caching. CRC is way for the results of queries to be cached in the database client process for reuse. [...] PHP OCI8 as a "client" of the database can use CRC. The cache is per-process, so plan carefully before caching large data sets. Tables that are candidates for caching are look-up tables where the network transfer cost dominates.

Like many of the other server-side tools Oracle has to offer, it's pretty simple to enable this caching. Before you had to add a custom bit to your query to tell it to enable the caching. Now it's as simple as setting it up on the CREATE or ALTER for the table - nothing extra for the developer to do.

tagged: oracle caching client result create alter

Link:

Kevin Schroeder's Blog:
What to make of TIOBE's PHP results
Mar 03, 2011 @ 18:20:29

Kevin Schroeder has some of his own thoughts on the recent results of the TIOBE index ranking the popularity of programming languages. PHP has slopped down two spots, replaced by Python and C++. He looks at the data TIOBE has to back it up and can't seem to find a reason why.

I decided to take a look and see what was going on behind the scenes by reading on the index definition to see if I could understand what happened. After reading through the definition I still don't know what happened, or even why it happened.

He goes through how the index data is created - search results from the top 6 hits in Alexa for each language result - and how he, basically, found nothing out of the ordinary. He points out that, because of inconsistencies like this, the TIOBE index shouldn't be regarded as much more than a loose guide. Since it's based on hard-coded search strings, it'll never be a true judge of "popularity" overall.

tagged: tiobe popularity result drop python c

Link:

Chris Jones' Blog:
PHP OCI8 and Oracle 11g DRCP Connection Pooling in Pictures
Feb 22, 2011 @ 16:44:46

Chris Jones has posted some "pictures" of the performance that an Oracle database sees when it uses the connection pooling versus the normal connect/allocate sort of connection with the Oracle OCI8 driver for PHP. As you can see, the differences in memory consumption are huge.

Here is a screen shot from a PHP OCI8 connection pooling demo that I like to run. It graphically shows how little database host memory is needed when using DRCP connection pooling with Oracle Database 11g. Migrating to DRCP can be as simple as starting the pool and changing the connection string in your PHP application.

He also describes the differences between the pooled and non-pooled connections (to the developer it's as easy as putting ":pooled" in the connect string) in his graphs, and notes that using the pooling doesn't just have to be for large site - smaller sites can benefit too.

tagged: oci8 oracle connection pooling performance graph result

Link:

W3Techs.com:
Highlights of web technology surveys, Nov. 2010: 3/4 of all websites are based on PHP
Nov 03, 2010 @ 15:19:30

According to a new article on the W3Tech.com site today, around three quarters of all websites are based on PHP. They've run their own survey to gather the results about the use of several different languages like ASP.NET, Java, Ruby and, of course, PHP.

Our server-side programming language survey shows that a very remarkable 74.9% of websites use PHP, slightly increasing in the last year. ASP.NET technologies (presumably mostly C#) come in second, and a few percentages are left for Java. That's about it. The variety of programming languages used to develop websites is surprisingly small, considering that everyone and his dog develops websites these days. There is a lot of talk in the IT blogoshere about alternative languages such as Ruby and Python, but their real world usage is tiny compared to PHP.

They talk about some of the contributing factors to these numbers including the wide use of various PHP-based content management systems, the balance of high traffic versus low traffic sites and some breakdowns according to operating system, geographical area and a hint at how their survey operates to find the systems using PHP.

tagged: survey usage result programming language website

Link:

Andrey Hristov's Blog:
Replacing mysqli's Connection, Result and Statement classes
Jul 09, 2010 @ 15:31:03

On his blog today Andrey Hristov has a quick post that talks about two methods to extend the functionality that the mysqli extension offers in PHP with your own custom code.

Have you ever though about extending mysqli's classes. It's pretty simple to subclass the connection class mysqli. However, subclassing mysqli_result and mysqli_stmt is not so obvious, actually I though that it's even not possible. However, never say never! After discussing mysqli's OO interface for an hour yesterday [...] I found out how one can plug his own classes.

Two code examples are provided - one for extending the mysqli_result and the other extending the mysql_stmt class. You can find more about these and other classes the mysqli extension has to offer in this section of the PHP manual.

tagged: replace mysqli connection result statement class extend

Link:


Trending Topics: