Feed aggregator

How To Modernize Your Legacy PHP Application

Planet-PHP - ma, 14/04/2014 - 16:57

It is accomplished: “Modernizing Legacy Applications in PHP”, the book that will help you modernize your legacy PHP codebase, is complete. You can get it now it at https://leanpub.com/mlaphp.

Is your legacy PHP application composed of page scripts placed directly in the document root of the web server? Do your page scripts, along with any other classes and functions, combine the concerns of model, view, and controller into the same scope? Is the majority of the logical flow incorporated as include files and global functions rather than class methods?

If so, you already know that the wide use of global variables means that making a change in one place leads to unexpected consequences somewhere else. These and other factors make it overly difficult and expensive for you to add features and fix bugs. Working with your legacy application feels like dragging your feet through mud.

But it doesn’t have to be that way! Modernizing Legacy Applications in PHP will show you how to modernize your application by extracting and replacing its legacy artifacts. We will use a step-by-step approach, moving slowly and methodically, to improve your application from the ground up.

Moreover, we will keep your application running the whole time. Each completed step in the process will keep your codebase fully operational with higher quality. When we are done, you will be able to breeze through your code like the wind. Your code will be autoloaded, dependency-injected, unit-tested, layer-separated, and front-controlled.

From the Foreword by Adam Culp:

Developing with PHP has really matured in recent years, but it’s no secret that PHP’s low level of entry for beginners helped create some nasty codebases. Companies who built applications in the dark times simply can’t afford to put things on hold and rebuild a legacy application, especially with today’s fast paced economy and higher developer salaries. To stay competitive, companies must continually push developers for new features and to increase application stability. This creates a hostile environment for developers working with a poorly written legacy application. Modernizing a legacy application is a necessity, and must happen. Yet knowing how to create clean code and comprehending how to modernize a legacy application are two entirely different things.

But understanding how to use these refactoring processes on a legacy codebase is not straight forward, and sometimes impossible. The book you’re about to read bridges the gap, allowing developers to modernize a codebase so refactoring can be applied for continued enhancement.

Early reviews and testimonials from the feedback page:

  • “This is one of those books that PHP developers from all skill levels will be able to glean value from, and I know after just a single read-through that it will be an oft-referenced resource when I need to convert my old legacy-based procedural code into something cleaner, object-oriented, and testable.” (J. Michael Ward)

  • “As I followed the exercises in the book, my questions almost seemed to be anticipated and answered before the chapter was over. Structurally the book is very well paced. Chapters that I breezed over tended to be more useful than I thought they would be. I’ve been testing for years and I still picked up some useful tidbits about structuring my tests. Just having the step-by-step advice of an expert really made a difference.” (James Fuller)

  • “Reading through the book, it feels like you’re pair programming with the author. I’m at the keyboard, driving, and the author is navigating, telling me where to go and what to do next. Each step is practical, self-contained and moves you closer to the end goal you seek: maintainable code.” (Joel Clermont)

  • “This book helped me slay a 300k line of code giant and has allowed me to break out my shell. The refactored code has 15% code coverage for unit testing which grows every day.” (Chris Smith)

If you feel overwhelmed by a legacy application, “Modernizing Legacy Applications in PHP” is the book for you. Purchase it today and get started making your own life easier!

Categorieën: Open Source, PHP Community

Allan MacGregor: Working with Psysh

PHPDeveloper.org - ma, 14/04/2014 - 16:24

Allan MacGregor introduces you to Psych in his latest post today. Psysh is a runtime developer console, interactive debugger and REPL for PHP.

Psysh is actually more than a simple REPL it's also an interactive debugger; which means you can say goodbye to the endless barrage of var_dump() and die() statements. But do we really need another REPL for PHP, well honestly we could probably get by with the solutions currently available however Psysh has an extremely interesting Ace under the sleeve, it can also function as a realtime debugger.

He includes a few terminalcasts showing some of the commands Psysh offers from the expected output of variable value out to a handy link to the PHP documentation. An example of the useful object output is also included, enabling the showing of methods and properties.

Link: http://coderoncode.com/2014/04/03/working-with-psysh.html

Community News: Packagist Latest Releases for 04.14.2014

PHPDeveloper.org - ma, 14/04/2014 - 15:09
Recent releases from the Packagist:

Database .NET 11 released!

Postgresql.org - ma, 14/04/2014 - 02:00

Database .NET v11 is an innovative, powerful and intuitive multiple database management tool, With it you can Browse objects, Design tables, Edit rows, Export data and Run queries with a consistent interface. Free, All-In-One, Portable, Standalone (No Installation) and Multlanguage.

New features from version 10.1 to 11.0:
  • Compatible with the latest versions of PostgreSQL.
  • Updated to Npgsql.dll 2.1.3
  • Added Support for JSON data type of PostgreSQL
  • Added Support for renaming all objects of PostgreSQL
  • Added Executing SQL Statements from a text file
  • Added Displaying Row Count of tables
  • Added Displaying Connection time
  • Added Data Editor for View objects
  • Added Search Table Data
  • Added Empty Table
  • Added New Connection Manager
  • Added New Object Navigator
  • Added Script All Table Data (INSERTs)
  • Added IntelliSense for Cross-schema table access
  • Added Selected Text to Query Builder
  • Added Dynamic Context Menu[?]
The new version is immediately available for download.
Categorieën: PHP Community

Barman 1.3.1 released

Postgresql.org - ma, 14/04/2014 - 02:00

14 April 2014: 2ndQuadrant is proud to announce the release of version 1.3.1 of Barman, Backup and Recovery Manager for PostgreSQL.

This minor release introduces support for concurrent backup using physical file based copy through "rsync", in conjunction with pgespresso, a new open source extension available for PostgreSQL 9.2 and 9.3. Concurrent backup allows database administrators that rely on Barman, to finally offload backup operations to a streaming replicated standby server, opening new important scenarios in disaster recovery architectures of PostgreSQL 9.2+ database servers.

The "barman diagnose" command has been implemented to print important information about the system and the configuration of Barman, allowing users to provide detailed diagnostics data in case of support requests.

Version 1.3.1 fixes an important bug on recovery that was affecting only those users having tablespaces created inside the PGDATA directory. This behaviour was introduced in version 1.3.0.

Minor bugs have also been fixed.

Many thanks for funding towards the development of this release go to Adyen (www.adyen.com).

For a complete list of changes, see the "Release Notes" section below.

Links

Release notes

  • Added support for concurrent backup of PostgreSQL 9.2 and 9.3 servers that use the "pgespresso" extension. This feature is controlled by the "backup_options" configuration option (global/server) and activated when set to "concurrent_backup". Concurrent backup allows DBAs to perform full backup operations from a streaming replicated standby.
  • Added the "barman diagnose" command which prints important information about the Barman system (extremely useful for support and problem solving)
  • Improved error messages and exception handling interface
  • Fixed bug in recovery of tablespaces that are created inside the PGDATA directory (bug introduced in version 1.3.0)
  • Fixed minor bug of unhandled -q option, for quiet mode of commands to be used in cron jobs (bug introduced in version 1.3.0)
  • Minor bug fixes and code refactoring

Download

About Barman

Barman (Backup and Recovery Manager) is an open source administration tool for disaster recovery of PostgreSQL servers written in Python. It allows your organisation to perform remote backups of multiple servers in business critical environments and help DBAs during the recovery phase. Barman’s most requested features include backup catalogues, retention policies, remote backup and recovery, archiving and compression of WAL files and backups. Barman is distributed under GNU GPL 3.

Categorieën: PHP Community

Hawk Autentication considered harmful.

Planet-PHP - zo, 13/04/2014 - 21:05

I was asked recently to add support for Hawk to sabre/http. It kinda seemed like a fun addition, but I'm building an increasing grudge, up to a point where I've nearly lost interest.

Missing documentation

The documentation is incomplete. The author points to his own javascript-based implementation as the reference, but 1700 lines of javascript code is simply not as easy to read as a plain-english reference.

In addition, the version of the protocol (currently 2.0) appears to be locked to the javascript library, and not the actual protocol.

This means that if bugs get fixed in the javascript source, the protocol version gets a bump. Leaving us no way to figure out something changed in the protocol, unless you're willing to go through the diffs for the source.

Uses the used hostname and port as part of the signed string

The both the hostname and the port are part of the signed string, unlike alternatives like AWS authentication and Digest.

The only case where this would actually be relevant, is if there's two endpoints with identical urls, and re-uses the same keys and secrets, and a identical request on the same url would be unwanted.

The drawback is that many service don't know what url was originally being used by a client, due to the use of reverse proxies.

Now we're forced to create a mechanism where the reverse proxy sends the original host header to the client.

Could have built upon Digest auth

Digest has a lot of good things going for it, and has a great deal of overlap in features.

Hawks strengths here are that it uses a stronger hash algorithm (hmac-sha256) and unlike Digest, it there's no need for pre-flighted requests to discover the service nonce. The latter is also the author's main concern with using Digest instead, as stated in the FAQ.

An answer to that would have been rather simple though. Any server could simply hardcode and document their server-side nonce, rendering the initial negotiation optional, but still possible.

Furthermore, digest can be easily extended with new algoritms.

What to use instead?

I'd highly recommend using simply either HTTP Digest, or if you're looking for something a little bit more fancy, use Amazon's authentication header.

Some benefits:

  • They are tried and tested for many years.
  • Not a moving target.
  • Documented.
  • Easier to implement.
  • Have lots of sample implementations.

That being said, I will probably still add support to an upcoming version of sabre/http.

Categorieën: Open Source, PHP Community

Community News: Packagist Latest Releases for 04.13.2014

PHPDeveloper.org - zo, 13/04/2014 - 15:00
Recent releases from the Packagist:

Tips & tricks for capifony deployment

Planet-PHP - zo, 13/04/2014 - 14:30

In this blog post we want to share some tips & tricks for deploying with capifony which you might find useful as well.

Upload parameters files per server

Capifony already supports the upload of a parameters.yml file to servers during the deployment. This is done globally or for each stage separately, what is already documented as a cookbook. The parameters files don't need to be in the repository, they just have to be on the machine where you run the deployment.

In our project each server requires its own license key for an external service. For that reason we need a separate parameters.yml file for each server and can't use the stages to distinguish them. To solve this problem we created a capifony task which can upload a different parameters file to each server.

First, we define the separate files for the servers.

# app/config/deploy/prod.rb
server 'server1.example.com', :app, :web, :primary => true, :parameters_file => 'production1.yml'
server 'server2.example.com', :app, :web, :primary => true, :parameters_file => 'production2.yml'

The directory of the files is set as a variable.

# app/config/deploy.rb
set :parameters_dir, "app/config/parameters"

Now comes the main part, we create a new task for uploading the file.

# app/config/deploy.rb
task :upload_parameters, :except => { :parameters_file => nil } do
  servers = find_servers_for_task(current_task)
  servers.each do |server|
    parameters_file = server.options[:parameters_file]

    origin_file = parameters_dir + "/" + parameters_file if parameters_dir && parameters_file
    if origin_file && File.exists?(origin_file)
      ext = File.extname(parameters_file)
      relative_path = "app/config/parameters" + ext

      if shared_files && shared_files.include?(relative_path)
        destination_file = shared_path + "/" + relative_path
      else
        destination_file = latest_release + "/" + relative_path
      end

      run "#{try_sudo} mkdir -p #{File.dirname(destination_file)}", :hosts => server

      capifony_pretty_print "--> Uploading " + parameters_file + " to " + server.host
      top.upload(origin_file, destination_file, { :hosts => server })
      capifony_puts_ok
    end
  end
end

This task is very similar to the one of the cookbook. We use the :except option to run this task only for servers which have the parameters_file property defined.

Then you can run the task.

  • For a shared parameters file: after 'deploy:setup', 'upload_parameters'
  • For an unshared parameters file: before 'deploy:share_childs', 'upload_parameters'
Generate parameters files per server

Instead of uploading the parameter files they can also be generated during the deployment. This can be used if you don't want to copy around files and just want to import another parameters file inside the parameters.yml. For this a slightly different task is needed.

# app/config/deploy.rb
task :generate_parameters, :except => { :parameters_file => nil } do
  servers = find_servers_for_task(current_task)
  servers.each do |server|
    parameters_file = server.options[:parameters_file]
    ext = File.extname(parameters_file)
    relative_path = "app/config/parameters" + ext

    if shared_files && shared_files.include?(relative_path)
      destination_file = shared_path + "/" + relative_path
    else
      destination_file = latest_release + "/" + relative_path
    end

    run "#{try_sudo} mkdir -p #{File.dirname(destination_file)}", :hosts => server

    capifony_pretty_print "--> Generating parameters file on " + server.host
    run "#{try_sudo} echo -e \"imports:\\n    - { resource: parameters/#{parameters_file} }\" >#{destination_file}", :hosts => server
    capifony_puts_ok
  end
end

The rest remains the same as for uploading the parameters files.

With this solution, the parameters.yml files have to be committed to the repository. We decided to do this because it makes the maintenance easier, e.g. we see the changes directly in our merge/pull requests.

Update schema with multiple entity managers

If you need an entity manager for updating the schema, which is not the default one, you can set a variable. All doctrine tasks in capifony will use this variable.

set :doctrine_em, 'custom_em'

But if you have multiple entity managers and want to update the schema for all of them, a little more work is required.

# Default entity manager
after 'deploy:create_symlink', 'symfony:doctrine:schema:update'

# Custom entity manager 1
after 'deploy:create

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

Categorieën: Open Source, PHP Community

Can Great Apps Be Written in PHP – An Interview Series

Planet-PHP - za, 12/04/2014 - 20:00

I read an old post, circa 2010, on the MailChimp blog a little while ago, about their experience using PHP.

It struck a chord with me, because the sentiments they shared I’ve felt myself, and heard echoed many times over the years. What are these sentiments, you may ask?

They’re the ones which infer that PHP, despite all its successes, really isn’t a true programming language. They’re the ones which intimate that, no matter how good you are, no matter what you’ve achieved, if you’re a PHP programmer, well, you’re really not a true developer, yet.

They’re the ones which suggest, or is that presuppose, that you should really become one of the cool kids developing in Ruby, Python, or Go; basically anything other than PHP. After all, what can you really do with PHP, right?

Continue reading %Can Great Apps Be Written in PHP – An Interview Series%

Categorieën: Open Source, PHP Community

Community News: Packagist Latest Releases for 04.12.2014

PHPDeveloper.org - za, 12/04/2014 - 15:01
Recent releases from the Packagist:

Getting Started with Assetic

Planet-PHP - vr, 11/04/2014 - 19:00

There was a time when asset management meant little more than inserting a tag or two and a couple of <script> tags into your html.

Nowadays, though, that approach just won’t cut it. There’s performance, for one thing. Assets are a significant performance drain both in terms of file size and the number of HTTP requests - optimizing both has become an essential part of the development process. This has been exacerbated by the proliferation of mobile devices.

Also, as client-side applications have become more and more sophisticated, managing dependencies amongst scripts and libraries has become increasingly complex.

Furthermore, technologies such as Less, Compass and Coffeescript require assets to be compiled, adding yet another step to the process of managing assets.

In this article I’m going to look at a PHP package called Assetic which helps manage, compile and optimize assets such as scripts, stylesheets and images.

Continue reading %Getting Started with Assetic%

Categorieën: Open Source, PHP Community

Matthias Noback: There's no such thing as an optional dependency

PHPDeveloper.org - vr, 11/04/2014 - 18:19

In his latest post Matthias Noback suggests the idea that there's no such thing as an optional dependency when it comes to working with packages and Composer.

On several occasions I have tried to explain my opinion about "optional dependencies" (also known as "suggested dependencies" or "dev requirements") and I'm doing it again: "There's no such thing as an optional dependency." I'm talking about PHP packages here and specifically those defined by a composer.json file.

So that everyone's on the same page, he starts with an example of a true dependency in a sample adapter class. He asks the usual question - "what's needed to run this code?" - and looking a bit deeper at the "suggested" packages. As it turns out, some of these dependencies turn into actual requirements when you need certain features of the tool. He points out that this is a problem with quite a few packages in the Composer ecosystem and proposes a solution - splitting packages based on requirements. He gives an example based on his adapter with a Mongo requirement split off into a "knplabs/gaufrette-mongo-gridfs" package that's more descriptive of the requirements.

Link: http://php-and-symfony.matthiasnoback.nl/2014/04/theres-no-such-thing-as-an-optional-dependency/

SitePoint PHP Blog: How to Speed Up Your App's API Consumption

PHPDeveloper.org - vr, 11/04/2014 - 17:51

The SitePoint PHP blog has some advice posted today from Jacek Barecki about how you can speed up your use of other APIs with a few performance increasing tips.

In the process of creating a PHP application you may come to a point when keeping it isolated from remote resources or services may become a barrier in its development. To move along with the project you may employ different API services to fetch remote data, connect with user accounts on other websites or transform resources shared by your application. [...] But using APIs in an incorrect way can quickly lead to performance issues and lengthen the execution time of your script. If you're looking for a way to avoid it, consider implementing some of the solutions described in the article.

He recommends four things you can think about doing to help make the most effective use of these services:

  • Make multiple requests at a time
  • Separate API calls from the app main flow
  • Build a smart cache engine
  • Master the API documentation
Link: http://www.sitepoint.com/speed-apps-api-consumption/

HHVM Blog: Hack Developer Day 2014: Keep Hacking

PHPDeveloper.org - vr, 11/04/2014 - 16:40

On the Facebook HHVM blog today there's a post about the Hack Developer Day they recently held in Menlo Park. The event brought in developers for a day of presentations from the Hack/HHVM engineers.

150+ Members of the PHP and developer community came to Facebook headquarters and joined over 2000 people online for presentations by the engineers of Hack and HHVM. Afterwards we held a five hour hackathon, where the attendees worked with those engineers to write Hack code, either by converting current codebases or writing new code from scratch.

For those that weren't able to attend or are interested in catching up on what was presented, they've posted videos of all of the sessions in a YouTube playlist as well as PDFs of all the slides. If you want the short version of what was presented, there's a quick list in the post or you can read a recap on the Facebook Engineering blog.

Link: http://hhvm.com/blog/4685/hack-developer-day-2014-keep-hacking

PHP 5.6.0beta1 released

Planet-PHP - vr, 11/04/2014 - 02:00
The PHP development team announces the immediate availability of PHP 5.6.0beta1. This release adds new features and fixes bugs and marks the feature freeze for the PHP 5.6.0 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! PHP 5.6.0beta1 comes with a number of new features, including: A new method called fread() to the SplFileObject classA new static method called createFromMutable() to the DateTimeImmutable classA new function called hash_equals()Support for marks to the PCRE extensionSupport for asynchronous connections and queries to the Pgsql extensionFor 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.0beta1 please visit the download page. Windows binaries can be found on windows.php.net/qa/. Our second beta should show up on the 24th of April. Thank you for helping us make PHP better.
Categorieën: Open Source, PHP Community

PHP mysqlnd memory optimizations: from 49MB to 2MB

Planet-PHP - do, 10/04/2014 - 20:58

Inspired by Antony, Andrey has implemented a memory optimization for the PHP mysqlnd library. Depending on your usage pattern and the actual query, memory used for result sets is less and free’d earlier to be reused by the PHP engine. In other cases, the optimization will consume about the same or even more memory. The additional choice is currently available with mysqli only.

From the network line into your script

Many wheels start spinning when mysqli_query() is called. All the PHP MySQL APIs/extensions (mysqli, PDO_MySQL, mysql) use a client library that handles the networking details and provides a C API to the C extensions. Any recent PHP will default to use the mysqlnd library. The library speaks the MySQL Client Server protocol and handles the communication with the MySQL server. The actions behind a users mysqli_query() are sketched below.

The memory story begins in the C world when mysqlnd fetches query results from MySQL. It ends with passing those results to the PHP.

PHP script mysqli extension/API mysqlnd library MySQL *.php *.c mysqli_query()     PHP_FUNCTION(mysqli_query)     MYSQLND_METHOD(query)     simple_command(COM_QUERY)     COM_QUERY   store_result()     return result set  

The new memory optimization is for buffered result sets as you get them from mysqli_query() or a sequence of mysqli_real_query(), mysqli_store_result(). With a buffered result set, a client fetches all query results into a local buffer as soon as they become available from MySQL. In most cases, this is the desired behaviour. The network line with MySQL becomes ready for a new command quickly. And, the hard to scale servers is offloaded from the duty to keep all results in memory until a potentially slow client has fetched and released them.

The result buffering happens first at the C level inside the mysqlnd library. The buffer holds zvals. A zval is internal presentation structure for a plain PHP variable. Hence, think of the mysqlnd result buffer as a list of anonymous PHP variables.

PHP script mysqli extension/API mysqlnd library MySQL *.php *.c …   store_result()     Buffer with zvals (MYSQLND_PACKET_ROW),
think: PHP variables   The default: reference and copy-on-write

When results are to be fetched from the mysqlnd internal buffers to a PHP script, the default behaviour of mysqlnd is to reference the internal buffer from the PHP script. When code like $rows = mysqli_fetch_all($res) is executed, first $rows gets created. Then, mysqlnd makes $rows reference the mysqlnd internal result buffers. MySQL results are not copied initially. Result set data is kept only once in memory.

PHP script mysqli extension/API mysqlnd library MySQL *.php *.c …   store_result()     Buffer with zvals ("/>

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

Categorieën: Open Source, PHP Community

How to Speed Up Your App’s API Consumption

Planet-PHP - do, 10/04/2014 - 18:00

In the process of creating a PHP application you may come to a point when keeping it isolated from remote resources or services may become a barrier in its development. To move along with the project you may employ different API services to fetch remote data, connect with user accounts on other websites or transform resources shared by your application.

The ProgrammableWeb website states that there are currently more than ten thousand APIs available all over the web so you’d probably find a lot of services that can be used to extend your PHP app’s functionality. But using APIs in an incorrect way can quickly lead to performance issues and lengthen the execution time of your script. If you’re looking for a way to avoid it, consider implementing some of the solutions described in the article.

Continue reading %How to Speed Up Your App’s API Consumption%

Categorieën: Open Source, PHP Community

OpenSSL Serious Security Bug: Does it Affect Your PHP sites?

Planet-PHP - do, 10/04/2014 - 11:39
By Manuel Lemos
Just a few days ago it was publicly announced a serious security bug called Heartbleed that affects secure sites based on the OpenSSL library.

Read this article to learn more about this security problem, how to test if your Web server or SSH server is vulnerable, how it may affect your PHP sites, what you should do to fix the problem.
Categorieën: Open Source, PHP Community

Postgres Open 2014 - Opens the Call for Papers

Postgresql.org - do, 10/04/2014 - 02:00

Postgres Open 2014 will be held in Chicago, IL, at the Hotel Sax, September 17 - 19, 2014. It will feature two full days of multiple parallel tracks of PostgreSQL presentations (September 18 - 19th) from both local and global speakers, covering a wide range of topics. In addition we will also be offering a separate day of tutorials (Wednesday, September 17th). For more information about the conference, please see our website http://postgresopen.org/2014

The Program Committee is currently accepting proposals for presentations at the conference. We are interested in submissions from both seasoned PostgreSQL experts and people new in the community, from both locals and representatives of the global community. In short, from anybody who has an interesting story to tell about PostgreSQL, whether deeply technical or story about a successful (or failed) usage. All presentations are 45 minutes, with time for questions. Talks can be submitted via the website: http://postgresopen.org/2014/callforpapers/

Our early-bird ticket registration will open in May 19, 2014 and are available through June 30, 2014, after which tickets will go up to their regular price.

Finally, we are also looking for sponsors! We several tiers of sponsorship, to make sure there is a choice for everybody. If you are interested, please see the Postgres Open sponsor page http://postgresopen.org/2014/becomesponsor/

We look forward to seeing you in Chicago in September!

Categorieën: PHP Community
Inhoud syndiceren