The Blog

PHP

Simple script that can save you from blacklist.

Posted on

This simple php scrips can be run by cron job once an hour to let you know if the qmail queue is getting full.


$x = shell_exec('/usr/local/psa/admin/sbin/mailqueuemng -s');

$y = explode("\n", $x);

foreach($y as $z){
$a = explode(":", $z);
$out[trim($a[0])] = trim($a[1]);
}

if ($out['Messages total'] > 100) {

mail('[email protected]', 'Email Problems', print_r($out, true));
}

Posted in Linux, PHP, PLESK Leave a comment

Symfony2 Doctrin2 encode password using prePersist Event Listener

Posted on

Service needs to look like this

services:
    user.listener:
        class: AppBundle\EventListener\UserListener
        arguments: [ "@security.password_encoder" ]
        tags: [ { name: doctrine.event_listener, event: prePersist } ]

Listener should look like that

// AppBundle\EventListener\UserListener.php

namespace AppBundle\EventListener;

use Doctrine\ORM\Event\LifecycleEventArgs;
use AppBundle\Entity\User;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;

class UserListener
{
    protected $container;

    public function __construct(UserPasswordEncoderInterface $encoder)
    {
        $this->encoder = $encoder;
    }

    public function prePersist(LifecycleEventArgs $args)
    {
        $entity = $args->getEntity();

        $encodedPassword = $this->encoder->encodePassword($entity, $entity->getPassword());
        $entity->setPassword($encodedPassword);
    }
}
Posted in Symfony2 Leave a comment

Install ssh2_connect for php on Windows

Posted on
  • Download DLL library from this link.http://pecl.php.net/package/ssh2
  • Extracted the archive’s content and:
    • placed php_ssh2.dll and php_ssh2.pdb files in the ext folder (e.g. C:\php\ext);
    • copied libssh2.dll file to C:\Windows\system32 and (if you got Win64) C:\Windows\SysWOW64 folder(s);
    • add or enable extension=php_ssh2.dll in php.ini

 

Posted in PHP 1 Comment

Loading assets from a different server

Posted on

In a production environment you’ll eventually want to load assets (images, CSS and JS) from a different server. Perhaps you’re running your own asset server or you’re even using a CDN. This will require the files to be linked with an absolute URL. But in your development environment you don’t want this – you want assets to be loaded directly from the same server.
Read More

Posted in Symfony2 Leave a comment
« Previous PageNext Page »