1

One of our email parsing scripts is having a problem using imap functions:

Fatal error: Call to undefined function imap_open()

IMAP is definitely enabled, it was compiled with php and shows up in the phpinfo() and when doing get_loaded_extensions() or extension_loaded("imap") Is there any reason why these functions may not be accessible?

IMAP version is 2007e and PHP is 5.3.

Edit 1: This is running on a mac server (OSX 10.5.7) the script using the imap function is in /var/***/ I tried putting a test file in /Library/WebServer/Document (the web root) using imap_open with the exact same details and it seems to work.

The way it is setup worked before a PHP update - is there any reason for it to stop working? I know I could move the email script into the webserver documents dir but I would also like to know why it would stop working the way it was before - could it be the way php is configured?

Tjkoopa
  • 2,298
  • 1
  • 17
  • 20
  • What's the output of var_dump(get_extension_funcs('imap')); ? – VolkerK Jul 08 '09 at 09:11
  • Too long to post, but it shows all the imap functions (71) in an array. (includes imap_open) – Tjkoopa Jul 08 '09 at 09:41
  • And you put this code snippet in exactly the script file where the call to imap_open() doesn't work, right before the call to imap_open() ? I.e. you see imap_open() in the var_dump output _and_ "all to undefined function imap_open()" both at the same time? – VolkerK Jul 08 '09 at 10:44
  • Good point, the script only runs every half hour so I just made a test file in the same dir - will put it in the normal class now, should run in about 5 mins. – Tjkoopa Jul 08 '09 at 10:56
  • 1
    ah, it's not even invoked the same way as your test script? "only runs every half hour so" sounds like a cronjob? That means it could use a completely different php version or at least a completely different configuration (file). – VolkerK Jul 08 '09 at 11:09

1 Answers1

3

With

echo get_cfg_var('cfg_file_path');

you can find out which php.ini has been used by this instance of php. You will probably see that the php apache-module (or is it php-cgi?) and the php cli version (used by your cronjob) are using different .ini files.
Depending on how you've installed php (and how this version of php was compiled) the apache module might also parse additional .ini files that your cli version does not. To check if this is the case run

<?php phpinfo(); ?>

in your webserver and look for an entry "additional .ini files parsed".
In any case you have to take care that the configuration used by the cli version includes the extension=php_imap... directive.

VolkerK
  • 95,432
  • 20
  • 163
  • 226
  • I checked the crontab after your last comment and she .sh script it was running specified the wrong php instance - I amended it and it works. Spot on answer - thanks. – Tjkoopa Jul 08 '09 at 13:08