muppet77 Posted September 2, 2011 Share Posted September 2, 2011 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 ); } Quote Link to comment https://forums.phpfreaks.com/topic/246261-php-not-work-when-cron-jobbed/ Share on other sites More sharing options...
muppet77 Posted September 2, 2011 Author Share Posted September 2, 2011 it takes 5-10 seconds to execute when i run it in a browser - could it be that this is too long for GoDaddy and it gets timed out early doors?? Quote Link to comment https://forums.phpfreaks.com/topic/246261-php-not-work-when-cron-jobbed/#findComment-1264681 Share on other sites More sharing options...
WebStyles Posted September 2, 2011 Share Posted September 2, 2011 for use with cron jobs, you should have the path to php inserted into the top of the file, like this: (also confirm that you have php CLI installed and running) #!/usr/local/bin/php -q <?php ... (rest of script) Quote Link to comment https://forums.phpfreaks.com/topic/246261-php-not-work-when-cron-jobbed/#findComment-1264732 Share on other sites More sharing options...
muppet77 Posted September 2, 2011 Author Share Posted September 2, 2011 Thanks mate. I have many other cron jobs working with php scripts that work perfectly. I will try your suggestion. thanks Quote Link to comment https://forums.phpfreaks.com/topic/246261-php-not-work-when-cron-jobbed/#findComment-1264747 Share on other sites More sharing options...
WebStyles Posted September 2, 2011 Share Posted September 2, 2011 keep in mind that /usr/local/bin/php is the path to MY php instalation, yours may be slightly differtent Quote Link to comment https://forums.phpfreaks.com/topic/246261-php-not-work-when-cron-jobbed/#findComment-1264758 Share on other sites More sharing options...
muppet77 Posted September 2, 2011 Author Share Posted September 2, 2011 ok, thanks. I will try that. some scripts do work and others don't. I will try your idea in an hour or so when home. would it explain though why some of php scripts cron perfectly though? Quote Link to comment https://forums.phpfreaks.com/topic/246261-php-not-work-when-cron-jobbed/#findComment-1264760 Share on other sites More sharing options...
WebStyles Posted September 2, 2011 Share Posted September 2, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/246261-php-not-work-when-cron-jobbed/#findComment-1264763 Share on other sites More sharing options...
muppet77 Posted September 2, 2011 Author Share Posted September 2, 2011 /home/content/m/u/p/muppet77/html does that sound a feasable route? Quote Link to comment https://forums.phpfreaks.com/topic/246261-php-not-work-when-cron-jobbed/#findComment-1264772 Share on other sites More sharing options...
muppet77 Posted September 2, 2011 Author Share Posted September 2, 2011 so #!/home/content/m/u/p/muppet77/html -q added Quote Link to comment https://forums.phpfreaks.com/topic/246261-php-not-work-when-cron-jobbed/#findComment-1264773 Share on other sites More sharing options...
muppet77 Posted September 2, 2011 Author Share Posted September 2, 2011 unsuccessful. :~( Quote Link to comment https://forums.phpfreaks.com/topic/246261-php-not-work-when-cron-jobbed/#findComment-1264777 Share on other sites More sharing options...
WebStyles Posted September 2, 2011 Share Posted September 2, 2011 the path must be to your PHP INTERPRETER There's no way your interpreter is called html and there's no way it's in your home directory. Quote Link to comment https://forums.phpfreaks.com/topic/246261-php-not-work-when-cron-jobbed/#findComment-1264778 Share on other sites More sharing options...
muppet77 Posted September 2, 2011 Author Share Posted September 2, 2011 how do I find it? Quote Link to comment https://forums.phpfreaks.com/topic/246261-php-not-work-when-cron-jobbed/#findComment-1264782 Share on other sites More sharing options...
WebStyles Posted September 2, 2011 Share Posted September 2, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/246261-php-not-work-when-cron-jobbed/#findComment-1264785 Share on other sites More sharing options...
muppet77 Posted September 2, 2011 Author Share Posted September 2, 2011 the clc? not sure how I check that. I have another script that auto tweets to Twitter and works via cron, so it is possible. Quote Link to comment https://forums.phpfreaks.com/topic/246261-php-not-work-when-cron-jobbed/#findComment-1264787 Share on other sites More sharing options...
WebStyles Posted September 2, 2011 Share Posted September 2, 2011 did you check the file permissions ? Quote Link to comment https://forums.phpfreaks.com/topic/246261-php-not-work-when-cron-jobbed/#findComment-1264792 Share on other sites More sharing options...
DavidAM Posted September 2, 2011 Share Posted September 2, 2011 $_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. Quote Link to comment https://forums.phpfreaks.com/topic/246261-php-not-work-when-cron-jobbed/#findComment-1264796 Share on other sites More sharing options...
muppet77 Posted September 2, 2011 Author Share Posted September 2, 2011 perfect! SOLVED. i just deleted the IF clause and it works. Many thanks to everyone, and i hope that helps someone else aswell! :D Quote Link to comment https://forums.phpfreaks.com/topic/246261-php-not-work-when-cron-jobbed/#findComment-1264801 Share on other sites More sharing options...
muppet77 Posted September 2, 2011 Author Share Posted September 2, 2011 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 ); Quote Link to comment https://forums.phpfreaks.com/topic/246261-php-not-work-when-cron-jobbed/#findComment-1264802 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.