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

Tideways.io:
PHP Session Garbage Collection: The unknown performance bottleneck
May 09, 2016 @ 17:49:22

On the Tideways.com blog there's a tutorial talking about the "unknown performance bottleneck" that can be caused by PHP's own session garbage collection. This garbage collection happens when sessions expire and they need to be removed from the current set/data source.

Here is one performance setting in your PHP configuration you probably haven't thought about much before: How often does PHP perform random garbage collection of outdated session data in your application? Did you know that because of the shared nothing architecture PHP randomly cleans old session data whenever session_start() is called? An operation that is not necessarily cheap.

It's his general advice to avoid PHP's random garbage collection (it happens one in every 1000 requests, randomly) and opt for a more consistent method using background scripts. He gives an example using the Laravel framework and it's modified session garbage collection happening every 50th request (making use of the Symfony Finder component). He points out the problem with its implementation and the negative impact it could have on large, highly used applications. They share some of their own statistics and how to change this default (modifying the lottery option and making a custom "cleanup" command).

tagged: session garbage collection performance bottleneck unknown modify laravel symfony

Link: https://tideways.io/profiler/blog/php-session-garbage-collection-the-unknown-performance-bottleneck

Chris Hartjes' Blog:
Monkey-patching Is for Closers
Jul 16, 2012 @ 14:09:51

In this new post to his blog Chris Hartjes looks at why "monkey patching is for closers" - how it should be avoided in favor of making the code itself more testable rather than "hack" with the patching.

The use of monkey-patching is extremely prevalent in the Ruby community and also to a certain extent in Python usage. I’m not going to go into length about their use of it except to say that it seems quite common and I think most developers are using it as a shortcut to counter what might be poor code architecture decisions.

He includes some example code, excerpted from a blogging system where runkit was originally use to test its functionally. He shows how some simple refactoring (adding input parameters, replacing a static method call, etc) makes it easier to unit test. Comments to the post include further refactoring ideas as well as a response from the original "offender" whose post sparked Chris' response.

tagged: monkey patch modify runkit unittest refactor

Link:

IBM developerWorks:
Getting Graphic with PHP
Jul 03, 2008 @ 15:20:00

The IBM developerWorks site has a new tutorial posted (registration/login required) talking about image creating in PHP using the GD library.

The purpose of this tutorial is to show you how to get started with the GD library and to provide a variety of techniques you can apply to your Web-page coding. The tutorial doesn't cover every GD function, but it teaches you the basics. The Resources section provides Web sites where you can learn more about using the GD library.

They go through the creation of sample images, working with gradients and lines, adding text, saving the image data out to a file and how to work with existing graphics to modify them.

tagged: tutorial graphic gd image gradient text modify lines

Link:

IBM developerWorks:
Use an XML database in PHP and Java applications
Apr 03, 2008 @ 14:33:36

The IBM developerWorks site has posted a tutorial (you'll need to log in) showing how to use native XML databases to speed up development time for your applications.

Native XML databases have grown in popularity along with XML, because data is stored as native XML, rather than through tables in a traditional database. Using a native XML database means that a change to the schema requires minimal changes to your code and no change to the database. PHP and Java developers can benefit greatly from using native XML databases

IT talks about how to connect to the database (in this case DB2), grab the XML data via a query and how to insert information back in via a web-based form. There's also an example showing how to make a "search" on the data and how to change the schema of the database on the fly as well.

tagged: xml database application tutorial db2 modify schema

Link:

DevShed:
A Quick Overview of the XML DOM Extension in PHP 5
Feb 26, 2008 @ 18:26:00

DevShed has started up a new tutorial series today with part one of their overview of the DOM extension that's included with PHP5:

Simply put, the DOM XML extension, as its name suggests, will permit you to work on XML documents by way of the DOM API. [...] In this article series I'll be discussing some of its most relevant methods and properties and accompanying all of these explanations with concise and instructive hands-on examples.

They look at using the DOM to create new documents, modify documents by adding additional nodes and converting over a SimpleXML document to be manipulated.

tagged: dom extension tutorial php5 build modify simplexml

Link:

Leo Buttiker's Blog:
Trevi is online!
Jan 08, 2008 @ 17:17:00

Leo Buttiker has posted a release announcement about the new framework they've developed - Trevi.

There're already thousands of web frameworks out there so I would sink into the ground if we really wrote another one. [...] Zend Framework looked like a nice solution. But what we probably liked most is that ZF allowed us to replace every component in the framework.

To this end, their "framework" isn't truly a new way of doing things - it's just a heavily modified version of the Zend Framework they've customized to fit their needs. Trevi is their own internal name for this release.

tagged: trevi zendframework online framework modify component custom trevi zendframework online framework modify component custom

Link:

Leo Buttiker's Blog:
Trevi is online!
Jan 08, 2008 @ 17:17:00

Leo Buttiker has posted a release announcement about the new framework they've developed - Trevi.

There're already thousands of web frameworks out there so I would sink into the ground if we really wrote another one. [...] Zend Framework looked like a nice solution. But what we probably liked most is that ZF allowed us to replace every component in the framework.

To this end, their "framework" isn't truly a new way of doing things - it's just a heavily modified version of the Zend Framework they've customized to fit their needs. Trevi is their own internal name for this release.

tagged: trevi zendframework online framework modify component custom trevi zendframework online framework modify component custom

Link:

Jonathan Street's Blog:
When scraping content from the web don't make it obvious
Nov 07, 2007 @ 17:26:00

Jonathan Street has a tip for those developers out there that have no other choice than scraping content from a remote site - don't make it obvious. He also includes a suggestion on how to make it a little less obvious.

A couple of hours ago I was playing around scraping some content from a website. All was going well until suddenly I couldn't get my script to fetch meaningful content. [...] The first thing I did was stop visiting the site for 15 minutes or so and then increase the time between requests. It briefly worked again but quickly stopped.

One simple change to his user agent string in his php.ini made the problem evaporate pointing to a user agent filtering happening on the remote side. His helpful hint involves two methods - one in just PHP and the other in cURL - to change the user agent that your scripts are sending. An even better sort of solution might be some sort of rotating array that would alternate between four or five strings to make things even more random.

tagged: scrape content remote server useragent filter modify phpini scrape content remote server useragent filter modify phpini

Link:

Jonathan Street's Blog:
When scraping content from the web don't make it obvious
Nov 07, 2007 @ 17:26:00

Jonathan Street has a tip for those developers out there that have no other choice than scraping content from a remote site - don't make it obvious. He also includes a suggestion on how to make it a little less obvious.

A couple of hours ago I was playing around scraping some content from a website. All was going well until suddenly I couldn't get my script to fetch meaningful content. [...] The first thing I did was stop visiting the site for 15 minutes or so and then increase the time between requests. It briefly worked again but quickly stopped.

One simple change to his user agent string in his php.ini made the problem evaporate pointing to a user agent filtering happening on the remote side. His helpful hint involves two methods - one in just PHP and the other in cURL - to change the user agent that your scripts are sending. An even better sort of solution might be some sort of rotating array that would alternate between four or five strings to make things even more random.

tagged: scrape content remote server useragent filter modify phpini scrape content remote server useragent filter modify phpini

Link:

Vinu Thomas' Blog:
Modifying your MySQL databases to be UTF-8 compliant
Dec 28, 2006 @ 13:47:00

There's a quick tip from Vinu Thomas on his blog for anyone having issues with UTF-8 data in a MySQL database (as accessed by PHP).

Most of us have had problems with UTF-8 problems in PHP and MySQL. Here's how to modify your database and table to be UTF-8 compliant. Most of the time we do set the character set to utf8 but forget to set the collation set to utf8.

He includes both SQL statements you'll need to make the transition - two ALTER statements that update the properties of a database and change the encoding on a specific table to UTF-8 compatibility.

tagged: mysql database modify utf8 compliant alter sql statement mysql database modify utf8 compliant alter sql statement

Link:


Trending Topics: