Categories
Laravel PHP

Mandrill mail from Laravel

The Laravel docs mention adding guzzlehttp/guzzle ~4.0 to composer.json for use with Mandrill’s API.

At the time of writing GuzzleHTTP 5.2 was current. Unclear why 5.2 is not suitable, but it gave the SSL Error 60  locally.

[code]
"require": {
"laravel/framework": "4.2.*",
"guzzlehttp/guzzle": "~4.0"
}[/code]

Seemed to fix it on Windows 8. PHP 5.6

Categories
Laravel PHP

Laravel’s PHAR Installer on Windows

Outdated Information. This was posted February 2014. Laravel seems to have moved away from the pre-packaged laravel.phar installation method. Install docs for Laravel 4.2 here

In addition to cloning from Git and installing via Composer Laravel can now be installed via a PHAR file.

The documentation is currently a little Linux centric.

On Windows download the laravel.phar file, open a command prompt in its location and run:

[code]
php laravel.phar new my-project-name
[/code]

That will create a new directory called my-project-name and install Laravel in there. This is a lot faster than installing via composer.

Categories
PHP

PHP’s Memory Caching Blackspot

PHP 5.4 came with APC (Alternative PHP Caching) which acted as both a byte-code cache (reducing the work of compiling the PHP files at runtime) and an in-memory object cache allowing the PHP app to store and retrieve arbitrary data.

PHP 5.5 is moving to Zend’s OpCache (bundled, but not enabled by default) which will replace APC’s function as a byte code cache. The gotcha is that OpCache does not (yet?) provide object caching that your app can use to store its own data.

So if you’re moving to PHP 5.5 you may find a bit of a  black spot when it comes to an automatically included memory cache. APCu looks to provide the object caching of APC, but it does require extra installation.

Categories
PHP

Pad and Trim Input Arrays

PHP function to get an input array to have only, and all of the keys specified. This is useful if you have an array of user input with fields as keys, and you want to pad to ensure all keys are present, while stripping any not part of the template array:
[php]<?php
/**
* Fill and strip array according to $keys
* @param array $input
* @param array $keys
* @param mixed $fill
* @return array
*/
function array_purge_fill($input, $keys, $fill = ”) {
$keys = array_flip($keys);
$input = array_intersect_key($input, $keys); //strip extra keys from input

//Add empty values for missing keys
$diff = array_diff_key($keys, $input);
$diff = array_fill_keys(array_flip($diff), $fill);

return array_merge($input, $diff);
}[/php]

Example:

[php]<?php $input = array( ‘name’=>’Mike’, ‘phone’=>’12345’, ‘extra_value’ => true );
$keys = array(‘name’, ‘phone’, ’email’);

$newInput = array_purge_fill($input, $keys);
//has name, phone, email keys. Email will be empty, ‘extra_value’ will be removed[/php]

Categories
PHP

APC on PHP5.4 Windows

APC (Alternative PHP Cache for bytecode caching and object storage) isn’t bundled with Windows.

This seemed to work (basic test on PHP 5.4.11). This Stackoverflow answer was helpful.

Other pages with Windows DLLs linked from that Stackoverflow discussion did not work for me.

Categories
PHP

PHP FTP Error – PORT Command Successful

If your PHP script that FTPs files starts failing with an error like this:

PHP Warning:  ftp_put() [function.ftp-put]: PORT command successful

Try using pasv mode.

<?php
$con = ftp_connect(ftp.example.com);
//...
ftp_pasv($con, true);
?>