Feed aggregator

Allan MacGregor: Working with Psysh

PHPDeveloper.org - Mon, 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 - Mon, 14/04/2014 - 15:09
Recent releases from the Packagist:

Database .NET 11 released!

Postgresql.org - Mon, 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.
Categories: PHP Community

Barman 1.3.1 released

Postgresql.org - Mon, 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.


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


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.

Categories: PHP Community

Hawk Autentication considered harmful.

Planet-PHP - Sun, 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.

Categories: Open Source, PHP Community

Community News: Packagist Latest Releases for 04.13.2014

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

Tips & tricks for capifony deployment

Planet-PHP - Sun, 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
        destination_file = latest_release + "/" + relative_path

      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 })

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
      destination_file = latest_release + "/" + relative_path

    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

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)

Categories: Open Source, PHP Community

Can Great Apps Be Written in PHP – An Interview Series

Planet-PHP - Sat, 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%

Categories: Open Source, PHP Community

Community News: Packagist Latest Releases for 04.12.2014

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

Getting Started with Assetic

Planet-PHP - Fri, 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%

Categories: Open Source, PHP Community

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

PHPDeveloper.org - Fri, 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 - Fri, 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 - Fri, 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 - Fri, 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.
Categories: Open Source, PHP Community

PHP mysqlnd memory optimizations: from 49MB to 2MB

Planet-PHP - Thu, 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)

Categories: Open Source, PHP Community

How to Speed Up Your App’s API Consumption

Planet-PHP - Thu, 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%

Categories: Open Source, PHP Community

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

Planet-PHP - Thu, 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.
Categories: Open Source, PHP Community

Postgres Open 2014 - Opens the Call for Papers

Postgresql.org - Thu, 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!

Categories: PHP Community

Introduction to JadePHP

Planet-PHP - Wed, 09/04/2014 - 19:32

There are dozens of templating engines out there, with options such as Smarty, Twig (used in the upcoming version of Drupal) and Blade (the default for Laravel) among the best known - as well as vanilla PHP, of course. Stepping away from PHP specifically, eRuby / ERB and Haml for Ruby / Ruby on Rails, and Javascript has scores of popular choices including Mustache, Handlebars, Hogan and EJS. Some have subtly different syntax, some more markedly so.

One which differs quite significantly from most is Jade, an engine usually associated with Javascript applications - it’s supported out-of-the-box by Express for Node.js, for example. It’s Jade I’m going to look at in this article; or more specifically the PHP port JadePHP.

Haml and Jade

It would be remiss to talk about Jade without mentioning Haml, from which Jade takes its inspiration - and indeed there are several libraries for using Haml with PHP. Jade shares its overall philosophy, which is to make templating “beautiful” and use what the authors describe as templating “haiku”. Whatever that actually means, there’s no denying Haml and Jade do share some characteristics which make them fundamentally different to most templating languages.

What’s the Difference?

Most templating engines involve writing the target markup and “injecting” it with placeholders and / or basic logic - a superset, in a sense. Jade still has placeholders and logic, but also provides a shorthand for writing XML-like elements. Generally that means html, although you can also use it for things like RSS as well as XML itself.

In fact if you wanted to, you could just use Jade as a shorthand for html without taking advantage of its more “traditional” templating features.

How to use the Repository

Rather frustratingly, the code is not currently available via Composer - although it should be a simple enough task to package it up, if anyone has an hour or two. You can get it to to work, however, by cloning the repository and include‘ing or require‘ing the included autoload.php.dist (the Github repository includes Symfony’s UniversalClassLoader).

Here’s an example, adapted from the one in the project’s README, which assumes that the repository has been downloaded into a directory called jade:


use Everzet\Jade\Dumper\PHPDumper,

$dumper = new PHPDumper();
$dumper->registerVisitor('tag', new AutotagsVisitor());
$dumper->registerFilter('javascript', new JavaScriptFilter());
$dumper->registerFilter('cdata', new CDATAFilter());
$dumper->registerFilter('php', new PHPFilter());
$dumper->registerFilter('style', new CSSFilter());

// Initialize parser & Jade
$parser = new Parser(new Lexer());
$jade   = new Jade($parser, $dumper);

$template = __DIR__ . '/template.jade';

// Parse a template (both string & file containers)
echo $jade->render($template);

This will compile the file template.jade and echo its contents.

Where you actually use this depends on your workflow, whether you’re using a framework, and so on. You could, perhaps, use a service such as Watchman, Guard or Resource Watcher to watch the filesystem for changes to your Jade templates, and compile them at the appropriate time during the development process.

Continue reading %Introduction to JadePHP%

Categories: Open Source, PHP Community
Syndicate content