php5 code on crontab failed

dmiebim
dmiebim used Ask the Experts™
on
Hi All,
I have a php5 script that runs well by manually. It connects a sybase db, makes same calculations and insert them in a sybase table. But, when I try to work it in crontab, I always getting this error;

"/usr/bin/php: error while loading shared libraries: libsybunic.so: cannot open shared object file: No such file or directory"

I've tried to put environment variables in the beginning of php code but didn't work.
Any idea?


Beginning of code is like this;

#!/usr/bin/php5 --
<?
        putenv ("SYBASE=/home/sybase");
        putenv ("SYBASE_OCS=OCS-15_0");
        putenv ("SYBASE_ASE=ASE-15_0");
        putenv ("SYBASE_SYSAM=SYSAM-2_0");
        putenv ("PATH=$SYBASE/bin:$SYBASE/$SYBASE_ASE/bin:$SYBASE/$SYBASE_OCS/bin:$SYBASE/$SYBASE_SYSAM/bin:$PATH");
        putenv ("LD_LIBRARY_PATH=$SYBASE/lib:$SYBASE/$SYBASE_ASE/lib:$SYBASE/$SYBASE_OCS/lib:$LD_LIBRARY_PATH");
     

        global $conn;
         $conn = sybase_connect('EBIMFS', 'radiousr', 'xxx');
........




Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2011
Top Expert 2016

Commented:
$SYBASE is undefined in the code snippet.  It looks like the script might depend on register_globals. See this page:
http://www.php.net/manual/en/security.globals.php
Hi dmiebim,
Looks to me as if the environment of your cron job is different from your own account (which is to be expected), and it seems that you might have already started looking down this path.
What is the full path to libsybunic.so?  One way to find it is by typing this at the UNIX/Linux command prompt:
    which libsybunic.so
or:
    locate libsybunic.so
Then make sure libsybunic.so's directory is in the:
    putenv ("PATH=...
line.

Or you could just login to your account, and type:
    echo $PATH
and make sure all the possibly relevant directories displayed are included in that
    putenv ("PATH=...
line.
Most Valuable Expert 2011
Top Expert 2016
Commented:
Agree with tel2 about the differing environment.  Here is a technique that I have used to debug CRON and other asynchronous jobs that do not have easy-to-read browser output.

At the logical top of the script, put
ob_start()

At the logical end of the script, put something like this:
phpinfo();
$msg = ob_get_contents();
mail("You@Your.org", "CRON OUTPUT", $msg);


Assuming the script runs without any parse errors, you will get an email containing all the browser output, followed by the PHP information about the working environment.

Author

Commented:
problem resolved

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial