Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

15 May 2012

RabbitMQ PHP in Ubuntu 12.04

Testing RabbitMQ PHP in Ubuntu 12.04
Examples for AMQP in official PHP site (last check 2012/05/15) not sync with API for PECL 1.0.1.
This is my version to test simple php amqp

emit_log.php:

// Create a connection
$cnn = new AMQPConnection(array('login'=>'guest', 'password'=>'abc123'));
$cnn->connect();

// Create a channel
$ch = new AMQPChannel($cnn);

// Declare a new exchange
$ex = new AMQPExchange($ch);
$ex->setName('logs');
$ex->setType(AMQP_EX_TYPE_FANOUT);
$ex->declare();

// Publish a message to the exchange with a routing key
$message = isset($argv[1]) ? $argv[1] : 'hello world message';
$ex->publish($message, 'routing.key');

receive_log.php:

// Create a connection
$cnn = new AMQPConnection(array('login'=>'guest', 'password'=>'abc123'));
$cnn->connect();


// Create a channel
$ch = new AMQPChannel($cnn);


// Declare a new exchange
$ex = new AMQPExchange($ch);
$ex->setName('logs');
$ex->setType(AMQP_EX_TYPE_FANOUT);


// Create a new queue
$q = new AMQPQueue($ch);
$q->declare();
$q->bind('logs', 'routing.key');


function cb($env, $q) {
    print $env->getBody()."\n";
}
// Read from the queue
$msg = $q->consume('cb');


Easier to manage rabbitmsq server with the rabbitmq_management than the rabbitmqctl
Example based on rabbitmq Publish/Subscribe tutorial

09 October 2009

Inconsistent PHP - I'm sick of it

PHP is inconsistent, sick of it. $needle or $haystack? Which one first? List of php function that inconsistent needle/haystack

helmi@gandalf:/usr/share/doc/php-doc/html> grep -l needle *| grep ^function | sed 's/^function.//'| sed 's/.html$//'| sed 's/-/_/'
array_search
grapheme_stripos
grapheme_stristr
grapheme_strpos
grapheme_strripos
grapheme_strrpos
grapheme_strstr
iconv_strpos
iconv_strrpos
in_array
mb_stripos
mb_stristr
mb_strpos
mb_strrchr
mb_strrichr
mb_strripos
mb_strrpos
mb_strstr
mb_substr-count
stripos
str_ireplace
stristr
strpos
strrchr
str_replace
strripos
strrpos
strstr
substr_count


So I refer to php manual everytime use these functions, grrr. For vim, i override key binding for 'K' (:help K) - "Run a program to lookup the keyword under the cursor". In .vimrc
autocmd FileType php set keywordprg=~/bin/php_doc

and my ~/bin/php_doc

#!/bin/sh
FN=`echo $1 | sed 's/_/-/g'`
echo ********************** $FN **********************

echo $FN
w3m file:///usr/share/doc/php-doc/html/function.$FN.html