Help for running php as cli

Hi all.

I have procmail directing emails with certain subjects to a php script via a line similar to this in the procmailrc

| $HOME/blah/blah/script.php

i have chmodded the script to 755, and the shebang line of the script has the path given to me when i type in ‘which php’

however, after that the script dies.
viewing the procmail log
it says it gives it to the script, and everything is an unexpected error.
if i have <?php , it says ?php isn’t a directory
all lines after that are unexpected tokens.

any suggestions? i’ll post more specifics of people want them.

In order to run a PHP script on the command line, you need to pipe your values through the PHP binary itself with the script as the argument:

| /path/to/php $HOME/blah/blah/script.php

using the following recipie file:
| /usr/loca/bin/php $HOME/path/to/script

i get the following error logged:

/usr/local/bin/php: /usr/local/bin/php: No such file or directory

am i missing something with the piping?

try double checking your pahts. I think it was just a type in this post, but your first typed “loca” instead of local. type “whereis php” to verifi it’s location on your server.


turning on verbose logging showed that procmail was trying to execute 2 things
/path/to/php and /path/to/script

so i encaspulated the above line in quotes for

filter 0


  • ^subject:.*appraisal
    | “/usr/local/bin/php -f $HOME/path/email_test2.php”

where email_test2.php is a script that will send an email to a hardcoded address when called. it runs fine calling it from php-cli

sending a test email to procmail gives the following in the log:

procmail: [1935] Tue May 24 11:39:07 2005
procmail: Assigning "SHELL=/bin/sh"
procmail: Match on "^subject:.*appraisal"
procmail: Assigning "LASTFOLDER=/usr/local/bin/php -f $HOME/path/email_test2.php"
procmail: Executing "/usr/local/bin/php -f $HOME/path/email_test2.php"
procmail: Notified comsat: "inhouseapps@:/usr/local/bin/php -f $HOME/path/email_test2.php"
From Tue May 24 11:39:07 2005
Subject: appraisal
Folder: /usr/local/bin/php -f $HOME/path/email_test2 1260
/usr/local/bin/php -f $HOME/path/email_test2.php: /usr/local/bin/php -f $HOME/path/email_test2.php: No such file or directory

the script, while it says is executed, never sends me an email to indicate it works.

Well, simple; $HOME/path/email_test2.php doesn’t exsist. I think most likely the cause is $HOME isn’t set when this runs ($HOME is generally a shell thing, procmail isn’t executed within a shell, I believe).

Change your path to the fully qualified path and see if that works.

that doesn’t work either.

and it works for you on the command line? I don’t know what to say now… hrmm