Jump to content

php not work when cron jobbed?


muppet77

Recommended Posts

i have a php script that works perfectly by sending an new image to twitter api.

 

when i set a cron job it doesn't work.

 

is there any reason for this please?

 

thanks

 

if ( ! empty($_FILES)) {

  require 'tmhOAuth.php';
  require 'tmhUtilities.php';
  $tmhOAuth = new tmhOAuth(array(
    'consumer_key' => deleted,
    'consumer_secret' => deleted,
    'user_token' => 'deleted,
    'user_secret' => deleted,
    ));

$params = array('image' => "@temps/now.JPG;type=image/jpg;filename=now",);


  $code = $tmhOAuth->request('POST', $tmhOAuth->url("1/account/update_profile_image"),
    $params,
    true, // use auth
    true  // multipart
  );

}

Link to comment
Share on other sites

they shouldn't... the CLI extension (Command Line Interface) is what allows you to execute php files in a standalone environment. Because you're calling a file on it's own, the system needs to know where the interpreter for that specific language is. Also make sure the file permissions allow it to be executed by the appropriate user (the user you've defined in the cron job) : maybe the fact that some run and some don't is based on different permissions.

Link to comment
Share on other sites

I run my own servers, so I have access to everything. since you're on godaddy, you should read up on their instructions about php CLI and cron jobs. maybe they're even adding that line automatically to your scripts (some hosts do)... They have a lot of support documentation, so you're bound to find the answer.

did you also check the file permissions like I mentioned before?

Link to comment
Share on other sites

$_FILES is a global array that is created when a file is uploaded from a web page using a <FORM> tag. This array is not going to exist in a cron job. Since you are using if ( ! empty($_FILES)) { at the beginning of the script, the code inside the IF is not going to execute.
Link to comment
Share on other sites

so the correct code is

 

require 'tmhOAuth.php';
  require 'tmhUtilities.php';
  $tmhOAuth = new tmhOAuth(array(
    'consumer_key' => 'ynmInkV1p5wcQ77XBbrz0Q',
    'consumer_secret' => 'Hj1OEdzBd5pKlFPYjs2pPanmeT5YVKpxqC0I6TkOHU',
    'user_token' => '283990930-Mbbasdfw0Wc2m1IebFmsxXeUcotnR5aBZnjCe0eP',
    'user_secret' => 'xGzYqmzEOMiV1FwZujF8Nl87VLOEX7UlPa9u3FCZ4o',
    ));

$params = array('image' => "@temps/now.JPG;type=image/jpg;filename=now",);


  $code = $tmhOAuth->request('POST', $tmhOAuth->url("1/account/update_profile_image"),
    $params,
    true, // use auth
    true  // multipart
  );


Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.