Skip to content

Instantly share code, notes, and snippets.

@phalcon
phalcon / r.php
Last active December 19, 2015 00:59
<?php
$router = new \Phalcon\Mvc\Router();
$router->add('/:module/:controller/:params',
array(
'module' => 1,
'controller' => 2,
'action' => 'index'
)
@phalcon
phalcon / a.php
Last active December 18, 2015 00:19
<?php
class Data
{
protected $service;
public function setMyService($service)
{
$this->service = $service;
}
<?php
class Exception1 extends Exception
{
}
class Exception2 extends Exception
{
<?php
class Robots extends Phalcon\Mvc\Model
{
public function initialize()
{
$this->hasManyThrough(
'id',
'RobotsParts',
'robots_id',
@phalcon
phalcon / assets.php
Last active December 17, 2015 17:19
<?php
$manager = new Phalcon\Assets\Manager();
$js = $manager->get('js');
$js->addFilter(
new Phalcon\Assets\Filters\Jsmin(array(
'some-option' => 'some-value'
)
<?php
use Phalcon\DI,
Phalcon\Events\Manager as EventsManager,
Phalcon\Db\Adapter\Pdo\Mysql as Connection,
Phalcon\Mvc\Model\Manager as ModelsManager,
Phalcon\Mvc\Model\Metadata\Memory as ModelsMetaData;
$eventsManager = new EventsManager();
@phalcon
phalcon / orm-1.php
Last active December 17, 2015 12:29
<?php
use Phalcon\DI,
Phalcon\Events\Manager as EventsManager,
Phalcon\Db\Adapter\Pdo\Sqlite as Connection,
Phalcon\Mvc\Model\Manager as ModelsManager,
Phalcon\Mvc\Model\Metadata\Memory as ModelsMetaData;
$eventsManager = new EventsManager();

==================================== Yet Another Micro-Optimization Guide

On the internet, you can find many guides on micro-optimizing PHP, for small applications, these optimizations do not add any value to the application performance. In medium to large applications (depending on the complexity of the processes implemented), the summatory of all that saved overhead could improve the overall application performance.

Early optimization is the root of all evils, most of the time you need to be focused in creating amazing and maintaniable software rather than faster software. The following tips help to write faster PHP code, however if the volume of overhead saved is not considerable the application will perform without a noticeable difference.

I/O-bound is different from compute-bound

Be aware of the difference between code that is compute-bound (slow because it's doing a huge number of instructions) and code that is I/O bound (s

<?php
/**
* PhalconEye
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
*
<?php
/**
mysql> CREATE TABLE `modules` (
-> `moduleid` smallint(5) NOT NULL AUTO_INCREMENT,
-> `parentid` smallint(5) DEFAULT NULL,
-> `title` varchar(50) DEFAULT NULL,
-> PRIMARY KEY (`moduleid`)
-> ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;
Query OK, 0 rows affected (0.21 sec)