PHP

Install Drupal in php-fpm (fastcgi) with Apache and a chroot php-fpm

Using PHP-fpm is a way to push PHP execution outside of Apache, one of the main reasons to use it is freeing memory usage of PHP in the apache processes and allowing usage of a threaded Apache server. In this article we'll explain what this sentence means :-) and will detail installation and configuration of php-fpm for a Drupal project.

Votre notation : Aucun Moyenne : 5 (99 votes)
Étiquettes:

Tune your php settings for Drupal

m

In this article we'll study how to tune the php.ini settings for a Drupal host, how to manage variations of theses settings per Virtalhosts, and of course how to do it without the ugly .htaccess files.

Votre notation : Aucun Moyenne : 4.3 (8 votes)
Étiquettes:

Better rewriteRules for Drupal

Drupal comes with a default set of Rewrite Rules in the .htaccess file given by the project. In this article I'll try to provides some recipes for an enhanced mod-rewrite set.

  • getting rid of .htaccess
  • forbid usage of direct requests to index.php?q=foo (when clean url is activated)
Votre notation : Aucun Moyenne : 4.7 (12 votes)

Cache d’opcode APC sur serveur Debian

Définition Wikipédia : APC (pour Alternative PHP Cache) est une extension PECL (PHP Extension Community Library) libre et gratuite destinée à améliorer les performances des applications écrites en langage PHP en précompilant le code intermédiaire et en le plaçant dans …

Lire la suite »

Aucun vote pour l'instant.

De la bonne utilisation de strtr()

Essayez un jour de taper ceci :

<?php
$lockMessage
= "This container is currently being edited by %account";
$lockMessage = strtr($lockMessage, '%account', 'Anonymous');
?>

Votre notation : Aucun Moyenne : 5 (2 votes)
Étiquettes:

Amusons nous avec PHP, aujourd'hui : le JSON et le console

Le petit problème du jour est le suivant : dans une application fortement AJAX, jQuery en client side, PHP en server side, j'ai besoin d'effectuer le debug de requêtes AJAX provenant du client en POST contenant du JSON, et le retour du serveur, contenant, du JSON aussi!

Pour ceci, on pourrait utiliser Firebug, que tout le monde connait bien, mais ne m'occupant pas de la partie JS, mais du code PHP serveur, j'ai pas envie d'inspecter 3000 lignes de JS pour mettre un break point au bon endroit.

Pour ceci, petit feinte, utiliser l'onglet Console de Firebug, et PHP en command line.

Votre notation : Aucun Moyenne : 5 (1 vote)
Étiquettes:

How to retrieve boolean values from PHP's configuration

It might seem trivial to retrieve boolean settings from php's configuration with the use of ini_get(). As an example, we will try to know if php is running in safe_mode or not. There is a ini directive for this, which can be defined in php.ini or in httpd.conf .

in php.ini :

safe_mode = 0

in httpd.conf :

php_admin_value safe_mode 0

Now, let's try to guess its value from a php script.

Votre notation : Aucun Moyenne : 5 (3 votes)
Étiquettes:

Tip of the day, get a views row primary key value

This is often a problem when you pragmatically manipulate views row's : finding the primary key value of the current row being explored.
Let's have an example : A node base table based view.

<?php
 
// Load the view, and stick to default display for sample purpose.
 
$view = views_get_view('my_node_view');
 
$view->set_display(NULL);
 
// Then, execute it.
 
$view->pre_execute();
 
// You will set some other options here, like limit, pager, offset.
 
$view->execute();
?>

What then?

Aucun vote pour l'instant.
Étiquettes:

Code snippet: human readable to machine name

This PHP code snippet compute nice machine name (i.e. with only alpha numerical characters, keeping inside hyphens) from a formated human readable name.

Useful for some automatic machine name identifiers computing from human readable arbitrary titles, I use it sometime in Drupal modules.

<?php
/**
* Helper that generates a machine name using a provided human readable name.
*
* @param string $human_name
*   Human readable name.
*
* @return string
*   Machine name cleaned-up of any special chars.
*/
function human_to_machine($human_name) {
  return
strtolower(preg_replace(array(
   
'/[^a-zA-Z0-9]+/',
   
'/-+/',
   
'/^-+/',
   
'/-+$/',
  ), array(
'-', '-', '', ''), $human_name));
}
?>

Votre notation : Aucun Moyenne : 5 (2 votes)

A simple (and ugly) time-saving line of code

Update on Mai, 28 : Added a new code snippet.

Sometimes, when you are trying to debug PHP code, you'll get an ugly WSOD, without any error messages in PHP error log.

When this happens, it's always really difficult to find out why. The lack of message tells you that you you didn't wrote something that bad, but bad enougth for the framework you are working with to partially catch your error without really crashing.

So, how can you resolve this?

Votre notation : Aucun Moyenne : 5 (2 votes)
Étiquettes: