Change from PHP3 to PHP5 problem

Discussion in 'PHP' started by countrydj, Jan 10, 2011.

  1. #1
    I have moved a script, that worked perfectly well, from a server running PHP3 to a server running PHP5.
    The script runs from a cron job. This is the cron command:
    php /home/countrymusic/countrymusic.org.uk/html/webstats
    The script that this runs is (part of it):
    # get the webstats.html file
    $statfile="logs/webstats.html";
    $stats = join('',file($statfile));
    (this is line 9 referenced below)
    When I run the script from /etc/cron.d/webstats.sh, I get the following error:
    # /etc/cron.d/webstats.sh
    PHP Warning: file(logs/webstats.html): failed to open stream: No such file or directory in /home/countrymusic/countrymusic.org.uk/html/webstats on line 9
    PHP Warning: join(): Bad arguments. in /home/countrymusic/countrymusic.org.uk/html/webstats on line 9

    When I run with:
    # php /home/countrymusic/countrymusic.org.uk/html/webstats
    PHP Warning: file(logs/webstats.html): failed to open stream: No such file or directory in /home/countrymusic/countrymusic.org.uk/html/webstats on line 9
    PHP Warning: join(): Bad arguments. in /home/countrymusic/countrymusic.org.uk/html/webstats on line 9

    I get the same return.
    However, when I run from the directory that the script is in, it works fine:
    # php webstats


    You have new mail in /var/spool/mail/root
    [root@redvelvet html]#

    This proves that the errors in the first 2 examples are incorrect.

    I have been using this script for a few years now without any problems.
    This means that the problem must be how PHP5 works, but I can't figure out why.

    Has anybody got any ideas ???

    Many thanks,

    John C
     
    countrydj, Jan 10, 2011 IP
  2. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #2
    join() is deprecated, use implode() instead...theirfore search and replace join with implode
     
    danx10, Jan 10, 2011 IP
  3. countrydj

    countrydj Active Member

    Messages:
    41
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #3
    Hi danx10...
    Thanks for taking the time to respond to my post.
    I did try implode() in place of join() but it made no difference.

    However, since I mde the post, I had an idea:
    I changed:
    $statfile="logs/webstats.html";
    to
    $statfile="/home/countrymusic/countrymusic.org.uk/html/logs/webstats.html";
    and that worked for me.

    Has anybody got any idea WHY it needed the full linux path ???

    John C
     
    countrydj, Jan 10, 2011 IP