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
https://forums.phpfreaks.com/topic/246261-php-not-work-when-cron-jobbed/
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.

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?

$_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.

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
  );


Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.