Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8510263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:39:15+00:00 2026-06-11T03:39:15+00:00

I am trying to execute a php file hosted on linode with crontab. Here’s

  • 0

I am trying to execute a php file hosted on linode with crontab.

Here’s what i’ve done so far.

i added a line to :

/etc/crontab ('crontab -e' is used too)

And I want to execute this file every 2 mins.

*/2 * * * * /usr/bin/php /srv/www/path/to/my/php/file.php

Here’s the code in my php file for testing

// Set error reporting
error_reporting(-1);
ini_set('display_errors', 'On');
ini_set('html_errors', 'On');
ini_set('allow_url_fopen', 'On');

$fh = fopen('gallery.xml', 'w+');
fwrite($fh, $_SERVER['REQUEST_TIME']);
fclose($fh);

Both the php file and xml file are with 777 permission.
If I open the php file directly in the browser, the xml file can record the variable.
But nothing happen when I used the crontab. It seems that it didn’t work for me.

I am using Linode and debian 6.

Am I doing anything wrong? Please give some suggestion. Thanks.

Bryant

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T03:39:16+00:00Added an answer on June 11, 2026 at 3:39 am

    You may need to correctly set your working directory or use absolute paths for your fopen() as cron’s default working directory is the home directory of whatever account the job’s running under, so it may be ~/root or ~/yourusername (see this stackexchange question too). You may try this:

    */2 * * * * ( cd /srv/www/path/to/my/php/ ; /usr/bin/php -q file.php )
    

    or this:

    */2 * * * * cd /srv/www/path/to/my/php/ && /usr/bin/php -q file.php
    

    and the difference is that 2nd one will not fire PHP if cd failed which is perfectly what we want as if cd failed there will be no file.php to launch.

    You can also set executable bit (i.e. chmod a+x file.php) and add this as very first line to your script:

    # /usr/bin/php -q
    

    so you’d be able to invoke your script as any other app or script (i.e. ./file.php). then your crontab entry would look:

    */2 * * * * cd /srv/www/path/to/my/php/ && ./file.php
    

    And do not use cryptic “-1” in your error_reporting(). It tells nothing. Use E_ALL or anything that ends in valid setting and is more self explanatory than -1.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying to execute this mysql query in my php file however I
I'm trying to execute a java program to sign a pdf file with php
Iam trying to find the setting, where i can have PHP execute other file
I am trying to use a cronjob to execute a php file on a
I am new to PHP and JavaScript development, I am trying to execute this
I am trying to write a bash or PHP script that will execute a
Im trying to execute a .bat file remotely in a powershell script. The code
While trying to execute the following lines only the last two statements are displayed(Here
i'm trying to execute a php in the console, but each time i run
I am trying to import a txt/csv file into my postgres database from php

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.