SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    Join Date
    Oct 2009
    Location
    London, UK
    Posts
    382
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Question RewriteRule stopping cron job

    Hi there,

    In my public_html folder I have the following .htacces file:

    Code:
    Options +FollowSymLinks 
    RewriteEngine on 
    
    RewriteCond %{HTTP_HOST} site1.com
    RewriteCond %{REQUEST_URI} !^/site1
    RewriteRule ^(.*)$ site1/$1 [L]
    
    RewriteCond %{HTTP_HOST} site2.com
    RewriteCond %{REQUEST_URI} !^/site2
    RewriteRule ^(.*)$ site2/$1 [L]
    I also have a cron job running the following command:
    Code:
    /usr/bin/php5 /home/sites/{domain-name}/public_html/site2/backup_db.php
    If I disable the .htaccess file, the cron job will execute, otherwise it wont. I'm not really sure why this is happening, since the cron job is using an absolute path to a file on the server, and not making any requests through the server. Isn't it?

    Has anyone come up with this sort of thing before?

    Many thanks

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,097
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Cron should not connect via the website, no, but maybe your PHP script is?
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,679
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    MG,

    Rémon is correct about Adobe not running the CRON request.

    I believe you have an error in your CRON code:

    Code:
    /usr/bin/php5 /home/sites/{domain-name}/public_html/site2/backup_db.php
    I have a CRON job running using

    Code:
    /usr/local/bin/php -q /home/{account_name}/public_html/{php_script_name}
    Given that it's been working for me for over two years (on three accounts), I would recommend that you check your PHP executable location AND add the -q switch before the PHP filename that you want CRON to execute.

    NOTE 1: I cannot find the meaning of the -q switch so it may not be necessary -- just something to try if all else fails.

    NOTE 2: DreamHost's example is /usr/local/php5/bin/php /home/<USER NAME>/path/to/script.php, i.e., the php executable is in the binary directory of the php5 but does NOT use the -q switch.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  4. #4
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,242
    Mentioned
    155 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mickyginger View Post
    I also have a cron job running the following command:
    Code:
    /usr/bin/php5 /home/sites/{domain-name}/public_html/site2/backup_db.php
    If I disable the .htaccess file, the cron job will execute, otherwise it wont. I'm not really sure why this is happening, since the cron job is using an absolute path to a file on the server, and not making any requests through the server. Isn't it?

    Has anyone come up with this sort of thing before?
    Can you give us some background about what you script does? We don't necessarily need to see the code, but I think ScallioXTX is on the right track here. I'd bet that your script is trying to connect to your website over HTTP and the cron job is interfering with that part of the script.

    Quote Originally Posted by dklynn View Post
    NOTE 1: I cannot find the meaning of the -q switch so it may not be necessary -- just something to try if all else fails.
    Boy, that became a difficult challenge and I'm not even sure I found the proper meaning in the way you used it. What I found states it suppressed html output in older cgi versions. In PHP 5.2 the -q was deprecated.

    From: http://php.net/manual/en/features.commandline.php (first comment)
    i use emacs in c-mode for editing. in 4.3, starting a cli script like so:

    #!/usr/bin/php -q /* -*- c -*- */
    <?php

    told emacs to drop into c-mode automatically when i loaded the file for editing. the '-q' flag didn't actually do anything (in the older cgi versions, it suppressed html output when the script was run) but it caused the commented mode line to be ignored by php.

    in 5.2, '-q' has apparently been deprecated. replace it with '--' to achieve the 4.3 invocation-with-emacs-mode-line behavior:

    #!/usr/bin/php -- /* -*- c -*- */
    <?php

    don't go back to your 4.3 system and replace '-q' with '--'; it seems to cause php to hang waiting on STDIN...

  5. #5
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,679
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    cp,

    Thanks for that info. I was checking Apache.org for details on that (should have been a Linux website, I know ) and found nothing. Other website examples used the -q but gave no definition of that switch.

    I hope Micky gave it a try both with and without and will report back here with results.

    BTW, (belated) congrats on becoming a TL! Well deserved.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  6. #6
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,242
    Mentioned
    155 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dklynn View Post
    cp,

    Thanks for that info. I was checking Apache.org for details on that (should have been a Linux website, I know ) and found nothing. Other website examples used the -q but gave no definition of that switch.
    Not a problem, I had never seen that switch option before, so I was curious as to what it could possibly mean myself (and it was a challenge to find what little info about it I did find).

    Off Topic:

    Quote Originally Posted by dklynn View Post
    BTW, (belated) congrats on becoming a TL! Well deserved.
    Thanks!


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •