Tag Archive | php

Cron cannot run on Drupal: the drupal_goto() case

Sometimes you want to redirect a page to another on drupal. You can do this using a simple function called drupal_goto().

On few sites I’ve enabled the PHP filter module and then created a new page with PHP code input format with drupal_goto(‘node/2′) to redirect the current page to a specified node. Bad idea.

I’ve noticed that, after this change, cron.php operations failed, if you have Search module enabled. On cron new contents are indexed by the Search module: when it got my PHP page, it tries to index it but suddenly is redirected to another. You can also found an error like “Maximum function nesting level of ’100′ reached” on php error log, symptom of an indexing blocked by pages with drupal_goto inside.

Solution:

  1. Comment all drupal_goto() instruction in your site within pages.
  2. Use an alternative method to redirect from a node to another.
  3. Run cron from Status Report page: you can adjust indexed content per cron on Search configuration page (admin/settings/search on 6.x)

You can add a new block with PHP code inside or (better) create a new module for this simple block (with a simple PHP switch statement as content), displaying it only on specified pages (on the bottom of block configuration). But if you create a PHP block via UI, and you put that block on every page, your site could be loop, so creating a module is the cleanest and secure way (if something go wrong, you can delete your module from the codebase and correct it). You can also find some contrib modules for redirect on drupalmodules.com.

See also:

Fatal error: Maximum function nesting level of ’100′ reached, aborting!

PEAR install quick howto on Debian Lenny: Image_Graph

Tested on Debian Lenny.

Time elapsed before a working script < 10 minutes ;-)

Install PEAR installer:

# apt-get install php-pear

First, type:

pear -h

to get help.

On root shell type:

# pear install --alldeps Image_Graph

Install failed with error:

Failed to download pear/Image_Graph within preferred state “stable”, latest release is version 0.7.2, stability “alpha”, use “channel://pear.php.net/Image_Graph-0.7.2″ to install

Retype as:

# pear install --alldeps Image_Graph-0.7.2

Repeat for other alpha dependencies the same procedure, eg:

pear install --alldeps Numbers_Words-0.15.0

At last, you got:

Nothing to install

Now, you can find all installed packages on /usr/share/php.

ImageGraph is installed on /usr/share/php/Image/Graph.php.

You have to include it on your PHPs.

You can follow the Ian’s howto on:

http://www.phpbuilder.com/columns/ian_gilfillan20060503.php3

To start using PEAR Image_Graph.

Here the result using Ian’s code on my Linux box:

Image_Graph test, using Ian code

Image_Graph test, using Ian code

Additional info:

Hosting providers (eg. HostMonster) sometimes furnish simplified PEAR installation via CPanel. So, you can use local PEAR installation for developement, and online installation for production use.

Remember:

  • To check differences between local and production versions
  • To change include path! (say no to white screen!)

See also:

Raise Drupal files upload limit

  1. In your Drupal site, go to admin/settings/uploads
  2. Raise upload limits. If the value you want to insert is greater than PHP allowed value:
  3. On bottom of your .htaccess file (drupal/.htaccess) add these lines:
    # upload settings
    # cfr. http://it.php.net/manual/it/function.ini-set.php
    php_value post_max_size 50M
    php_value upload_max_filesize 50M
    php_value memory_limit 128M

    Change values as you wish.
  4. Return to admin/settings/uploads and watch changes on PHP limit.

See also:

HTTP 301 Page moved in Drupal

Scope: Move an old document to a new URL with HTTP 301 Permanent Redirect.

Module used (required if you don’t want to modify an existing page): URL aliases.

  1. Create a new page (or edit an old one). Select “PHP code” in input type.
  2. Fill the url alias box, with the old document path
  3. Insert the following code: <?php
    // Permanent redirection
    header(“HTTP/1.1 301 Moved Permanently”);
    header(“Location: http://www.yoursite.tld/location”);
    exit();
    ?>
  4. Save.

Note: Obviously you can’t see the page (you’ll be redirected to specified address), but you can edit or delete the page from admin/content/node. As admin, if you try to unpublish the page you’ll be redirected anyway: you have to delete the page to fix it.

See also: http://www.somacon.com/p145.php

Follow

Get every new post delivered to your Inbox.