Tag Archives: php

Installing the memcached PHP module for PHP 7 on Plesk

To install the PHP memcached module for PHP 7 on a Plesk 12.5 server running CentOS 6.8. Please note that this should also work on CentOS 7. We’re going to need to install the libmemcached dev package first: sudo yum install -y libmemcached-devel Next install the PHP 7 dev package. Since this is a Plesk server we install the Plesk version of this package: yum install -y plesk-php70-devel After installing these, cd to a temporary directory and clone the memcached module git repo and checkout the php7 branch: cd /tmp git clone https://github.com/php-memcached-dev/php-memcached.git git checkout php7 Next build the memcached module. Make sure to use the PHP 7 version of phpize and point to the PHP 7 version of php-config in the configure command: /opt/plesk/php/7.0/bin/phpize ./configure --disable-memcached-sasl --with-php-config=/opt/plesk/php/7.0/bin/php-config make sudo make install The module has been built and installed now. Now you only have to enable it: cd /opt/plesk/php/7.0/etc/php.d echo "extension=memcached.so" > memcached.ini Finally restart the webserver for the changes to take effect: sudo apachectl restart To make sure the module is loaded you can run: /opt/plesk/php/7.0/bin/php -m memcached should show up in the list of ...

(Read more...)

Installing HHVM 3.2 on a CentOS 6.7 server with Plesk

I wanted to play with HHVM a little bit to see if the speed gain is really as impressive as the benchmarks are showing. I tried this on a VPS running CentOS 6.7 and Plesk 11.5 and did run into a dependency collision using yum: Error: Package: psa-libxml-proxy-2.7.8-13032215.x86_64 (@PSA_11_5_30-dist) Requires: libboost_program_options.so.5()(64bit) Removing: boost-program-options-1.41.0-27.el6.x86_64 (@base) libboost_program_options.so.5()(64bit) Updated By: boost-program-options-1.54.0-7.el6.x86_64 (hop5) To get around this I first installed boost: wget http://www.hop5.in/yum/el6/boost-program-options-1.54.0-7.el6.x86_64.rpm rpm -ivh boost-program-options-1.54.0-7.el6.x86_64.rpm After installing boost you can install yum to install the hhvm 3.2 package, like so: cd /etc/yum.repos.d sudo wget http://www.hop5.in/yum/el6/hop5.repo yum clean all yum install hhvm To test if hhvm is working: hhvm --version This should return something like this: HipHop VM 3.2.0 (rel) Compiler: tags/HHVM-3.2.0-0-g01228273b8cf709aacbd3df1c51b1e690ecebac8 Repo schema: c52ba40f4a246d35a88f1dfc1daf959851ced8aa To use HHVM as a FastCGI handler from Apache/Nginx I first created a simple config file in /etc/hhvm (this directory should have been created installing the hhvm package). I named my config file hhvm.hdf and the content looks like this: Server { Port = 9000 Type = fastcgi FixPathInfo = true } Log { Level = Verbose UseLogFile = true Header = true File = /var/log/hhvm/error.log Access { * { File = /var/log/hhvm/access.log Format = %{X-Forwarded-For}i %l %u %t ...

(Read more...)

ZF2 routes with parameters containing slashes

The routing system of ZF2 is pretty flexible, which is nice in case you need something custom like I did today. I needed to be able to handle some Base64 parameter data and so it’s possible that this data will contain slashes. Therefore a plain vanilla segment route like this won’t work: 'my-route' => array( 'type' => 'Segment', 'options' => array( 'route' => '/myroute/:encdata', 'defaults' => array( 'controller' => 'Application\Controller\MyController', 'action' => 'handle-enc-data', 'encdata' => null, ), ), ), When my URL would be something like this the route wouldn’t be matched because of the slash characters inside of the Base64 parameter: http://my.local/myroute/c3ViamVjdHM/X2Q9MQ== A regex route can solve this problem. It’s actually pretty simple: 'my-route' => array( 'type' => 'regex', 'options' => array( 'regex' => '/reg4p/(?.*)', 'spec' => '/reg4p/%encdata%', 'defaults' => array( 'controller' => 'Application\Controller\MyController', 'action' => 'handle-enc-data', 'encdata' => null, ), ...

(Read more...)

Sending e-mail with alternative parts plus attachments

Today I was working on my MailService component in a ZF2 project. For this specific project I needed to be able to support alternative parts for text and html combined with attachments. The alternative parts are to allow less sophisticated mail readers, not capable of rendering html, to still read the message. When sending mail using the Zend\Mail\Message class you have to create a Zend\Mime\Message object and assign this object to the body of Zend\Mail\Message, using setBody(). The Zend\Mime\Message object contains the actual parts of the message and the Zend\Mail\Message is responsible for the mail headers. The default content-type of a Zend\Mail\Message is 'multipart/mixed'. This is usually perfect if you're only sending one text part and optionally one or more attachments, but if you want to support alternative parts (requires content-type 'multipart/alternate') AND attachments (requires 'multipart/mixed') then you have a little ...

(Read more...)

Adding custom fields to ZfcUser register form

The ZfcUser module ZfcUser is a Zend Framework commons module that handles basic use cases related to users. It takes care of handling the registration, logging in, logging out, authenticating and user profile management. It is a very well written module, allowing the user of the module to change the behavior without having to hack in the module’s codebase. Tip: never change the code of a vendor module. The problem A common use-case for the ZfcUser module is to add more fields to the registration form (i.e. a firstname and lastname or date of birth). Of course when I needed this functionality myself, I did a quick search and figured I wasn’t the only one needing this. However there were no real conclusive answers of how to do this. I did find one article[1] that helped me to get started. What I needed What I needed was the following: Add the extra fields to the registration form; Make sure the fielddata gets saved to the database when the user registers; Adding validators and filters to the custom fields; Changing the validator messages of the standard ZfcUser userfields; Changing the order of the fields in my registration form. How I accomplished it ...

(Read more...)

Dealing with alternative directory structures in ZF2

I just started diving into Zend Framework 2 after using Zend Framework 1 and even its early predecessors for years. And boy, things have changed! But after some initial reading I think I already see some major advantages, not in the last place the ModuleManager which really allows developers to create independent modules and share them with the community. Anyway on to the actual subject of this post: directory structure. A standard ZF2 application has the following directory structure: config data module public vendor init_autoloader.php public contains index.php and your .htaccess, plus your public web resources such as images javascript and css files. In a shared hosting environment running Plesk the directory structure is like this: httpdocs (this is the webroot) private statistics subdomains etc. We don’t want to put everything in the httpdocs directory, because that’s the public directory and is accessible from the outside world. In a Plesk environment the private directory is used for application level files that aren’t supposed to be accessible from outside. So the solution is pretty simple: Upload the contents from the public directory into httpdocs Upload the other directories (config, data, module, vendor and init_autoloader.php) into private After that you have to ...

(Read more...)

Datamapper pattern in PHP

PHPSep 19 20110 Comment

The object-relational gap is a general problem in every OO programming language. Since PHP joined the OO club a while ago this problem also came along with it. What I mean by object relational gap is the difference between a row in a relational database and an object in an OO language. Even though they have a lot in common, they aren’t the same thing and an OO programmer has to solve this by mapping rows to real objects. In an ideal world a programmer would only be concerned about objects and not database queries (and all the details that come with it) and many smart people have been trying to find the perfect solution to realize this. The result is many persistency frameworks that require the programmer to meta-tag class attributes to map them to database columns or write schemas to do the mapping. Some examples include JDO, JPA, (N)Hibernate, PDO and so on. In my opinion at this moment Microsoft offers the best solution with Linq, because it truly became part of the programming language and the programmer only has to deal with objects, while syntax checking happens at programming/compile time instead of runtime. Hopefully other languages (including ...

(Read more...)