Category: php
mcrypt and PHP 5.3 on Ubuntu Jaunty
My dedicated server still runs on ubuntu jaunty. I wanted to move on to php 5.3 (php 5.2.16 was the final release of the php 5.2 series). The issue is: php 5.3 is not available in jaunty repositories, because it will stay at 5.2.
Installing php 5.3 was simple, just add to:
the following:
2
deb-src http://php53.dotdeb.org stable all
Install the dotdeb pgp key:
Update the apt cache and upgrade php5:
But when you want to install phpmyadmin again now, it fails.
Luckily you can get that (mcrypt) by adding the lenny updates repository manually:
add:
Install the debian gpg:
Now update again:
and install php5-mcrypt flawlessly:
I commented out the new sources.list entries after the install, because I don't need them to be checked on every update.
Configure an Agavi Site with NGINX (using PHP-FPM)
I was used to configure my Agavi site with Lighttpd and recently switched to Nginx. The setup for Nginx was not so common to me, so I decided to write down what I had to do to configure it properly. Here is an example for dracoblue.net. Please change the parts of the script to suit your needs (the necessary parts are highlighted with "HINT:").
First of all install php5-fpm. On ubuntu I did it this way:
Now create a new file:
And add the following:
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
listen dracoblue.net:80;
# HINT: Add the servername, so Agavi is able to see that it's dracoblue.net
# Otherwise you'll get something like "localhost" here
server_name dracoblue.net;
location / {
# HINT: The directory where index.php is
root /home/dracobluenet/tags/1.0.0/pub;
index index.php;
# HINT: All files except those in "static" should be served by index.php
location ~* ^/(favicon.ico|robots.txt|static) {
break;
}
# HINT: All files except those in "static" should be served by index.php
if ($uri !~ "^/(favicon.ico|robots.txt|static|index.php)") {
rewrite ^/([^?]*)$ /index.php?/$1 last;
}
}
location ~ \.php($|/) {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
# HINT: The directory where index.php is + $fastcgi_script_name
fastcgi_param SCRIPT_FILENAME /home/dracobluenet/tags/1.0.0/pub$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
}
}
As you can see, for projects I usually have only a "static" folder which is not served by agavi. This keeps the amount of work low, which nginx needs to do for each request to decide whether it should be served by php or not. I also added robots.txt and favicon.ico since you usually have them in root, too.
Restart nginx.
PhpDebugToolbar 1.1.1 (for agavi) released
Today I am pleased to announce the availability of the Agavi PHP DebugToolbar for download. After the success of the Qos-Filter for agavi, I want to relaunch the useful agavi toolbar with a different name, a better look and feel and a way better code base.
What is PhpDebugToolbar?
Like you can see on the screenshot, it's a little Toolbar (written in JS+CSS), which keeps track of all stuff happening in your php agavi application.
So you can easily spot memory leaks, time exhausting tasks and extensive usage of database queries (with the doctrine extension).
Additionally it integrates easily into the logging system of agavi, just add the PhpDebugToolbarLoggerAppender class in your logging.xml!
Where to download Toolbar?
The source can be found on github now http://github.com/DracoBlue/PhpDebugToolbar, feel free to fork it and send pull request with new features!
Download for PhpDebugToolbar 1.1.1 (just 20KB) is also available here at dracoblue.net.
Short installation and configuration information can be found in the readme. Thanks to all contributors!
This is meant to be a lightweight alternative to the unofficial Agavi Debug Tools. It won't have FirePHP output or other neat features, which ship with Agavi Debug Tools. So if you need them: use adt, please!
What means T_PAAMAYIM_NEKUDOTAYIM?
This is an PHP-Tokenizer error, which just wants to tell you that there are two colons. ;)
Simple php task to run commandline in phing
In phing there is a task called exec. Even though it provides a "passthru"-property it's not really possible to directly get the response from the output.
Since I wanted to have direct output of all data, I created an adhock-task called "run". You can add it to your phing build file, by adding this tag right before the usage.
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class RunTest extends Task {
private $dir;
private $command;
function setCommand($command) {
$this->command = $command;
}
function setDir($dir) {
$this->dir = $dir;
}
function main() {
$this->log("Changing to: " . $this->dir);
chdir($this->dir);
$this->log("Executing: " . $this->command);
system($this->command);
}
}
]]></adhoc-task>
Remember, that this task does not check wether the directory exists and always requires it to be set. If you want to extend the task for your needs and mind to share it, feel free to post a reply!
Detect action/view/module and matched route in agavi
For each executed Module/Action(+View) there is an ExecutionContainer (AgaviExecutionContainer). So if you want to retrieve the current executed action, module or view, best is to do
2
3
$view = $this->getContext()->getViewName();
$module = $container->getModuleName();
But what if you want to retrieve the "real" action, the one and only for the request? That's a little bit more difficult, so here a short introduction how to deal with that.
Whenever the routing of agavi does the work for you, by turning the input data and webbrowser call of a user, into a action and validated data, it triggers an action, executes the view for the outputtype and fills the template. But Slots can be used from the view and trigger then again validation+action+view for their parameters.
This is why the real request route can not be found in the execution container and must be found somewhere else. In the Request.
2
3
'matched_routes', 'org.agavi.routing'
);
The route_names is nothing but an array, for instance:
2
3
4
5
'product.edit'
// because our current route is named "product.edit"
// in routing.xml
)
This information does help us indirectly to determine the action, which got called! Since the WebRouting has also a getRoute-method, which expects just a route_name, we can retrieve the info now easily:
2
3
4
5
6
7
// thatswhy list($first) = $array style
list($route_name) = $this->getContext()->getRequest()->getAttribute(
'matched_routes', 'org.agavi.routing'
);
$route = $this->getContext()->getRouting()->getRoute($route_name);
The new $route-Variable now holds an array of all information about the route. In our case, just some are interesting.
2
$action = $route['opt']['action'];
One really should use that only in case of a default slot, which is used directly in the output_types.xml or used on serveral different pages and has to determine on its own and by using module+action where it's actually embedded.




