tired high B{
Avatar

Sepehr Lajevardi

Vcard Download vCard   what is this?
Rss_icon

Recent Activity


Filter by:
All
  • Drupal PHP Extension

    This PHP extension for Drupal 7 currently adds C implementations to the frequently used check_plain and drupal_static Drupal functions.

    It is still experimental and it should not be used in production until you've thoroughly tested it. It has only been tested to work with PHP 5.3.2, however, it should work with PHP 5.2 as well. Test with a new Drupal installation first. If something goes wrong with drupal_static, you should know it right away, since Drupal will break if it's malfunctioning.

    INSTALLATION:

    1. Download, extract, and run phpize in the extension's directory.
    2. Run ./configure;make;make test
      If all tests passed then proceed by running make install.
    3. Restart your web server to load the new extension.
    4. Copy drupal_ext.patch to your Drupal's root directory
    5. Go to Drupal's root directory and apply the patch with "patch -p0 < drupal_ext.patch"
  • Passing PHP variables to Javascript and debugging with FireBug

    In this tutorial, I'll show a way to pass PHP/Drupal variables to javascript using drupal_add_js(), and a way you can debug javascript variables using the FireBug console.

    I'll start by creating a hook_menu() implementation to establish a page callback:

    <?php
    function helper_menu() {

     
    $items = array();
     
     
    $items['js-vars'] = array(
       
    'title' => t('Javascript Variables'),
       
    'description' => t('Javascript Variables'),
       
    'page callback' => 'helper_page_callback_js_vars',
       
    'access arguments' => array('access content'),
       
    'type' => MENU_CALLBACK,   
      );
     
      return
    $items;

    }
    ?>

    Next, I'll define the page callback:

    <?php
    function helper_page_callback_js_vars() {

     
    // include module javascript file
     
    drupal_add_js(drupal_get_path('module','helper') . '/js/helper.js');

     
    // define variables you'd like to pass to the DOM
     
    $js_vars = array(
       
    'js_vars' => array(
         
    'message' => t('Hello @username', array('@username' => $GLOBALS['user']->name)),
         
    'an_array' => array(
           
    'color' => t('red'),
           
    'name' => t('Eric'),
          ),
        ),
      );
     
     
    // pass variables to javascript
     
    drupal_add_js($js_vars, 'setting');
     
     
    // generate some page output
     
    return "TEST";

    }
    ?>

    And here is the contents of the javascript include file I stuck in my module directory:

    $(document).ready(function(){

      // debug variables directly in FireBug
      console.debug(Drupal.settings.js_vars);
     
      // popup mesage passed from Drupal
      alert(Drupal.settings.js_vars.message);
     
    });

    When viewing this page in a browser, you'll see the following. The javascript popup window is using variables passed directly from a Drupal/PHP array:
    javascript popup

    The console.debug() javascript method was used to send data directly to the FireBug console. If you open FireBug, you'll see the following:
    FireBug Console

    If you click on the Object shown, you can drill into the variables further:
    FireBug Console

  • Worst qualities of a programmer A few thoughts about what sets good programmers from bad programmers apart. An overview of distinguished qualities of bad programmers.
  • سربازهای يك‌چشم
    Stairway to Heaven, Rome, 1949Photographer...


    سربازهای يك‌چشم

    Stairway to Heaven, Rome, 1949
    Photographer Herbert List

  • PHP with nginx is about to Become a Lot Easier

    PHP version 5.4 will most likely include the PHP-FPM patch right in the core, which is great news for those of us who like to run PHP under the nginx web server. You may be asking, “What is PHP-FPM, and why should I care?”

    PHP-FPM is a patch for PHP core that handles the starting, stopping, and restarting of FastCGI processes as needed. This is important because nginx can only interface with PHP via FastCGI, unlike Apache, which loads the whole PHP environment right into itself. In addition to the performance benefits of nginx over Apache, running PHP via FastCGI rather than as an Apache module has its own benefits:

    • Lower memory usage (since extra nginx workers come without the whole weight of the PHP environment)
    • Easier permissions management (PHP can run as a different user than your server process)
    • If PHP crashes, nginx can keep going

    The downside is that, compared to mod_php, the nginx, PHP, and FastCGI stack takes significantly more work to set up. In the past, the way to make this setup work was to co-opt the spawn-fcgi script from the LightTPD project, and use that to start the FastCGI process. However, there are problems with that setup: it’s fragile (if a process stops it might not be restarted correctly) and it’s a pain to set up. After installing and configuring nginx, you need to download LightTPD, grab the script in question and configure it to start automatically, then configure everything to play nicely together. If you’re used to the out-of-the-box experience of mod_php, this might convince you to just upgrade your server instead of switching to the leaner, meaner nginx.

    Enter PHP-FPM. This patch bakes FastCGI process management right into PHP. So if you compile PHP with the FPM patch in place and the --enable-fpm configuration option, PHP will take care of starting and stopping processes as nginx requests them, with no additional configuration required. Of course, manually patching and compiling the PHP source is still more work than us lazy web developers would like to do, which is why it’s great news that, as of PHP 5.4, FPM will be folded into the core of the PHP project.

    This means that you’ll be able to download PHP, compile it with the --enable-fpm switch, and be off to the races running it with nginx in the same amount of time and effort it would take to set up with Apache.

    So if you’ve tried running PHP with nginx in the past and given up after jumping through the seventh hoop, I’d suggest you give PHP-FPM a try. At the moment there’s still a bit of hassle involved, but it’s improving all the time. In the meantime, you get to be the cool kid on the block with the sweet new toy!

    Related Posts

    1. The sysadmin view on “Why PHP”
    2. Installing PHP on Windows Just Got Easier
    3. PHP Server API Differences

  • Attack Against Apache.org

    This blog entry should serve as a model for open and transparent security self-reporting. I'm impressed.

    More news reports.

Next page