Caveat: This only works for web based cronjobs (which WPTB uses) and not all cronjobs. Anything that’s triggered through a url can use this script.
<?php // WPTB Mass Cronjob Script // http://wptweetbomb.com/strategy/fast-cron-job-setup // How To Use This Script // Save this code as a PHP file. Something like "wptb_cron.php" will do. // Enter your WPTB cron urls below, one per line in the "$data" variable. // Upload it to your server. Any server, in any location. // Setup ONE cronjob to run this script on that same server. $data = ' http://yourdomain.com/wp-content/plugins/wptweetbomb/wtb_go.php http://otherdomain.com/wp-content/plugins/wptweetbomb/wtb_go.php http://somedomain.com/wp-content/plugins/wptweetbomb/wtb_go.php '; // Don't edit below here unless you feel like tweaking some code. $urls = explode( "\n", trim($data) ); foreach( $urls as $url ) { get( $url ); } function get( $url ) { $curl = curl_init(); curl_setopt( $curl, CURLOPT_URL, $url ); curl_setopt( $curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)" ); curl_setopt( $curl, CURLOPT_HTTPHEADER, array("Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5", "Cache-Control: max-age=0", "Connection: keep-alive", "Keep-Alive: 300", "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7", "Accept-Language: en-us,en;q=0.5", "Pragma: ") ); curl_setopt( $curl, CURLOPT_ENCODING, "gzip,deflate" ); curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt( $curl, CURLOPT_TIMEOUT, 1 ); curl_setopt( $curl, CURLOPT_AUTOREFERER, 1 ); curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, 1 ); $html = curl_exec( $curl ); curl_close( $curl ); return $html; } ?>
You’re done. You now only have to change 1 cronjob and have it apply to all your blogs.
Each time the script runs it will trigger all the urls you’ve entered as part of the “$data” variable. Also this script will take one second per url to run. If you need more speed then make sure you’ve got cURL v.7.15.5+ and PHP v.5.2.3+ then change “CURLOPT_TIMEOUT” for “CURLOPT_TIMEOUT_MS” and it will go much faster.
I may bring something like this into the plugin in the future as well to help with bulk blog management.
No related posts.
11 Comments
sixthsense
23 Apr 2010
Thanks for this Andy, this looks promising.
But for those of us that do not know how to code, exactly how do we “setup one cronjob to run this script on that same server”?
Andy
24 Apr 2010
The normal way you setup a cronjob for a WPTB blog (or any other cronjob). Via command line, or as most people do, via cPanel.
Something like this…
wget -q -O /dev/null “http://yoursite.com/path/to/the/above/script.php”
Note: WP is screwing up the quotes, so change them for normal ones before using the above command…
Victor
24 Apr 2010
Just what I needed, thanks Andy.
Any idea what kind of upper limits I should be worrying about when using this? I’ve got a decent VPS with a bunch of blogs running on subdomains and I’m wondering if running one wtb_go.php per second 50+ times in a row will be too hard on my server.
What line would I edit to increase the delay between each cron? Or is that not even necessary?
Ricardo
25 Apr 2010
Nice solution, I will have to try it.
Do you think that running all cron at the same time will leave a footprint?
I would like to make cron work in a time interval, say from 12:00 pm to 2:00 pm, choosing any time between these two. Think it is possible?
Andy
08 May 2010
Victor – yes running WPTB 50 times in a second might make your server gasp for air if you’re not on a dedi.
To add some delay time, just add:
sleep( 10 );
on a new line, just after:
get( $url );
Change the number ’10′ to any number – that’s the number of seconds it will wait before continuing.
Alternatively you could change this line:
curl_setopt( $curl, CURLOPT_TIMEOUT, 1 );
For this:
curl_setopt( $curl, CURLOPT_TIMEOUT, 90 );
so that the script will wait until a blog has fully posted before doing the next one.
With both of these options you’ll need to massively extend the max script execution time in php.ini though.
Ricardo, I wouldn’t be worries about post-timestamp footprints across multiple blogs. If someone wants to uncover your network there are much easier ways to do it – just make sure you’re not interlinking the blogs (or if you are, do it with great care) and you’ll be fine.
You can certainly setup something up to run between 12pm and 2pm, but it’s beyond the scope of this script atm
Mal
04 Dec 2010
Now that is cool. I’ll try that.
an90
08 Dec 2010
Hi, Thanks for the tips. However, I only have 1 blog. I used ezCron software but I don’t know how to use it. Can someone please teach me how to? or rather give another cron softwares or something
Thank you.
admin
08 Dec 2010
@an90 – if you’ve only got 1 blog then you may as well just setup the cronjob normally in cPanel.
an90
08 Dec 2010
@admin
can i setup cron jobs for example this blog, using the cpanel of another blog/domain?
I did that already but it didn’t worked. I don’t if it’s just me.
Thanks.
are
10 Dec 2010
Hi,
Do you know what should I put in the cron command when using it by cpanel? i tried the command given in the tweetbomb general options but it seems to be not working. still not automatically post. what should I do?
admin
20 Feb 2011
Check the "email me" option for the cron jobs in cpanel.
Then use something like:
You'll get more info to go off then.
Leave a Comment