crontab and the include() function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • berkshire@gmail.com

    #1

    crontab and the include() function

    We recently upgraded php from 4.3.9 to 4.4.7. Everything is working
    well, except the php scripts running as cronjobs. It appears the
    problem is that these scripts utilize the include() function and these
    functions are utilizing relative paths. They worked just fine with
    the old version of php, but not with the new version.

    Anyone know what is causing this hiccup?

    TIA

  • Vladimir Ghetau

    #2
    Re: crontab and the include() function

    On Jun 14, 3:49 pm, berksh...@gmail .com wrote:
    We recently upgraded php from 4.3.9 to 4.4.7. Everything is working
    well, except the php scripts running as cronjobs. It appears the
    problem is that these scripts utilize the include() function and these
    functions are utilizing relative paths. They worked just fine with
    the old version of php, but not with the new version.
    >
    Anyone know what is causing this hiccup?
    >
    TIA

    Try using the server relative path in this case, or check the PHP.ini
    and setup some paths in there.

    So, instead of

    <?php

    include ('whatever.php' );

    ?>

    try


    <?php

    include('server/relative/path/to/the/whatever/file.php');

    ?>


    Cheers,

    Vladimir Ghetau

    Comment

    • Jerry Stuckle

      #3
      Re: crontab and the include() function

      berkshire@gmail .com wrote:
      We recently upgraded php from 4.3.9 to 4.4.7. Everything is working
      well, except the php scripts running as cronjobs. It appears the
      problem is that these scripts utilize the include() function and these
      functions are utilizing relative paths. They worked just fine with
      the old version of php, but not with the new version.
      >
      Anyone know what is causing this hiccup?
      >
      TIA
      >
      Are you specifying absolute paths or relative paths in your include()
      function?

      AFAIK, this behavior hasn't changed since the early days of PHP. Did
      you do something like change directories on the new version?

      --
      =============== ===
      Remove the "x" from my email address
      Jerry Stuckle
      JDS Computer Training Corp.
      jstucklex@attgl obal.net
      =============== ===

      Comment

      • berkshire@gmail.com

        #4
        Re: crontab and the include() function

        On Jun 14, 12:51 pm, Vladimir Ghetau <vladi...@pixel tomorrow.com>
        wrote:
        On Jun 14, 3:49 pm, berksh...@gmail .com wrote:
        >
        We recently upgraded php from 4.3.9 to 4.4.7. Everything is working
        well, except the php scripts running as cronjobs. It appears the
        problem is that these scripts utilize the include() function and these
        functions are utilizing relative paths. They worked just fine with
        the old version of php, but not with the new version.
        >
        Anyone know what is causing this hiccup?
        >
        TIA
        >
        Try using the server relative path in this case, or check the PHP.ini
        and setup some paths in there.
        >
        So, instead of
        >
        <?php
        >
        include ('whatever.php' );
        >
        ?>
        >
        try
        >
        <?php
        >
        include('server/relative/path/to/the/whatever/file.php');
        >
        ?>
        >
        Cheers,
        >
        Vladimir Ghetau
        Vladimir,

        Thanks for th reply. Unfortunately there are quite a few includes,
        and those includes have includes as well so changing hte include path
        from relative paths to absolute paths isn't a practical option for us
        at the momemnt.

        Comment

        • berkshire@gmail.com

          #5
          Re: crontab and the include() function

          On Jun 14, 12:57 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
          berksh...@gmail .com wrote:
          We recently upgraded php from 4.3.9 to 4.4.7. Everything is working
          well, except the php scripts running as cronjobs. It appears the
          problem is that these scripts utilize the include() function and these
          functions are utilizing relative paths. They worked just fine with
          the old version of php, but not with the new version.
          >
          Anyone know what is causing this hiccup?
          >
          TIA
          >
          Are you specifying absolute paths or relative paths in your include()
          function?
          >
          AFAIK, this behavior hasn't changed since the early days of PHP. Did
          you do something like change directories on the new version?
          >
          --
          =============== ===
          Remove the "x" from my email address
          Jerry Stuckle
          JDS Computer Training Corp.
          jstuck...@attgl obal.net
          =============== ===
          We are specifying relative paths - which worked just fine when our old
          version of php was installed. Upon upgrading these paths no longer
          work. To my knowledge no other settings in php were altered, however,
          there were some unused options that we left out when compiling the new
          version of php although I don't think any of them are related to this
          present problem.

          Comment

          • Jerry Stuckle

            #6
            Re: crontab and the include() function

            berkshire@gmail .com wrote:
            On Jun 14, 12:57 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
            >berksh...@gmai l.com wrote:
            >>We recently upgraded php from 4.3.9 to 4.4.7. Everything is working
            >>well, except the php scripts running as cronjobs. It appears the
            >>problem is that these scripts utilize the include() function and these
            >>functions are utilizing relative paths. They worked just fine with
            >>the old version of php, but not with the new version.
            >>Anyone know what is causing this hiccup?
            >>TIA
            >Are you specifying absolute paths or relative paths in your include()
            >function?
            >>
            >AFAIK, this behavior hasn't changed since the early days of PHP. Did
            >you do something like change directories on the new version?
            >>
            >--
            >============== ====
            >Remove the "x" from my email address
            >Jerry Stuckle
            >JDS Computer Training Corp.
            >jstuck...@attg lobal.net
            >============== ====
            >
            We are specifying relative paths - which worked just fine when our old
            version of php was installed. Upon upgrading these paths no longer
            work. To my knowledge no other settings in php were altered, however,
            there were some unused options that we left out when compiling the new
            version of php although I don't think any of them are related to this
            present problem.
            >
            Well, obviously something changed - either in your compile or your
            php.ini file. Did you have include_path set in your php.ini before?

            This is a problem with either relative or absolute paths - either way
            you can have problems when the path changes.

            --
            =============== ===
            Remove the "x" from my email address
            Jerry Stuckle
            JDS Computer Training Corp.
            jstucklex@attgl obal.net
            =============== ===

            Comment

            • Vladimir Ghetau

              #7
              Re: crontab and the include() function

              On Jun 15, 2:17 pm, berksh...@gmail .com wrote:
              On Jun 14, 12:51 pm, Vladimir Ghetau <vladi...@pixel tomorrow.com>
              wrote:
              >
              >
              >
              On Jun 14, 3:49 pm, berksh...@gmail .com wrote:
              >
              We recently upgraded php from 4.3.9 to 4.4.7. Everything is working
              well, except the php scripts running as cronjobs. It appears the
              problem is that these scripts utilize the include() function and these
              functions are utilizing relative paths. They worked just fine with
              the old version of php, but not with the new version.
              >
              Anyone know what is causing this hiccup?
              >
              TIA
              >
              Try using the server relative path in this case, or check the PHP.ini
              and setup some paths in there.
              >
              So, instead of
              >
              <?php
              >
              include ('whatever.php' );
              >
              ?>
              >
              try
              >
              <?php
              >
              include('server/relative/path/to/the/whatever/file.php');
              >
              ?>
              >
              Cheers,
              >
              Vladimir Ghetau
              >
              Vladimir,
              >
              Thanks for th reply. Unfortunately there are quite a few includes,
              and those includes have includes as well so changing hte include path
              from relative paths to absolute paths isn't a practical option for us
              at the momemnt.



              Hey B,

              How about defining a named constant, let's call it MY_SCRIPT_ROOT,
              that contains the closest path to your script, let's say

              <?php

              define('MY_SCRI PT_ROOT', '/dev/myscript');



              ?>

              and then, all the includes will go like this:



              <?php

              // an include for the /dev/myscript/includes/classes/php/
              bingoclass.php


              include (MY_SCRIPT_ROOT .'/includes/classes/php/bingoclass.php' );


              // an include for /dev/myscript/doit.php

              include (MY_SCRIPT_ROOT .'/doit.php');


              // an include for /dev/myscript/abc/yep.php

              include (MY_SCRIPT_ROOT .'abc/yep.php');

              ?>


              This is the best approach when you're dealing with strange paths that
              go on different levels and I'm using it with success.


              Vladimir

              Comment

              • Rik

                #8
                Re: crontab and the include() function

                On Sun, 17 Jun 2007 15:59:37 +0200, Vladimir Ghetau
                <vladimir@pixel tomorrow.comwro te:
                On Jun 15, 2:17 pm, berksh...@gmail .com wrote:
                >On Jun 14, 12:51 pm, Vladimir Ghetau <vladi...@pixel tomorrow.com>
                >wrote:
                >>
                >>
                >>
                On Jun 14, 3:49 pm, berksh...@gmail .com wrote:
                >>
                We recently upgraded php from 4.3.9 to 4.4.7. Everything is working
                well, except the php scripts running as cronjobs. It appears the
                problem is that these scripts utilize the include() function and
                >these
                functions are utilizing relative paths. They worked just fine with
                the old version of php, but not with the new version.
                >>
                Anyone know what is causing this hiccup?
                >>
                TIA
                >>
                Try using the server relative path in this case, or check the PHP.ini
                and setup some paths in there.
                >>
                So, instead of
                >>
                <?php
                >>
                include ('whatever.php' );
                >>
                ?>
                >>
                try
                >>
                <?php
                >>
                include('server/relative/path/to/the/whatever/file.php');
                >>
                ?>
                >>
                Cheers,
                >>
                Vladimir Ghetau
                >>
                >Vladimir,
                >>
                >Thanks for th reply. Unfortunately there are quite a few includes,
                >and those includes have includes as well so changing hte include path
                >from relative paths to absolute paths isn't a practical option for us
                >at the momemnt.
                >
                >
                >
                >
                Hey B,
                >
                How about defining a named constant, let's call it MY_SCRIPT_ROOT,
                that contains the closest path to your script, let's say
                >
                <?php
                >
                define('MY_SCRI PT_ROOT', '/dev/myscript');
                >
                >
                >
                ?>
                >
                and then, all the includes will go like this:
                >
                >
                >
                <?php
                >
                // an include for the /dev/myscript/includes/classes/php/
                bingoclass.php
                >
                >
                include (MY_SCRIPT_ROOT .'/includes/classes/php/bingoclass.php' );
                >
                >
                // an include for /dev/myscript/doit.php
                >
                include (MY_SCRIPT_ROOT .'/doit.php');
                >
                >
                // an include for /dev/myscript/abc/yep.php
                >
                include (MY_SCRIPT_ROOT .'abc/yep.php');
                >
                ?>
                >
                >
                This is the best approach when you're dealing with strange paths that
                go on different levels and I'm using it with success.
                I assume when using crons, the script doesn't get started in it's
                place/dir, but in the one where the cron starts.

                A simple:
                chdir(dirname(_ _FILE__));
                at the beginning of the script called by the cron should do it, every
                relative include would now be indeed relative to it's directory instead of
                relative to the cron.
                --
                Rik Wasmus

                Comment

                Working...