0

I have 2 functions about the wp_remote_get.

I wanna write all data ( functions output ) into the txt file ? How to ?

the functions;

// facebook
function hayransayisi(){
         $fb_id = '206938902665808';
         $count = get_transient('fan_count');
    if ($count !== false) return $count;
         $count = 0;
         $data = wp_remote_get('http://api.facebook.com/restserver.php?method=facebook.fql.query&query=SELECT%20fan_count%20FROM%20page%20WHERE%20page_id='.$fb_id.'');
   if (is_wp_error($data)) {
         return 'yok öylesi!!!';
   }else{
         $count = strip_tags($data[body]);
   }
set_transient('fan_count', $count, 60*60*24); // 24 hour cache
return $count;
} 

The twitter function ;

// Twitter
function rarst_twitter_user( $username, $field, $display = false ) {
$interval = 3600;
$cache = get_option('rarst_twitter_user');
$url = 'http://api.twitter.com/1/users/show.json?screen_name='.urlencode($username);

if ( false == $cache )
$cache = array();

if ( !isset( $cache[$username][$field] ) ) {
$cache[$username][$field] = NULL;
$cache[$username]['lastcheck'] = 0;
}

if( $cache[$username]['lastcheck'] < (time()-$interval) ) {

static $memorycache;

if ( isset($memorycache[$username]) ) {
$data = $memorycache[$username];
}
else {
$result = wp_remote_retrieve_body(wp_remote_request($url));
$data = json_decode( $result );
if ( is_object($data) )
$memorycache[$username] = $data;
}

if ( is_object($data) ) {
foreach ($cache[$username] as $key => $value)
if( isset($data->$key) )
$cache[$username][$key] = $data->$key;

$cache[$username]['lastcheck'] = time();
}
else {
$cache[$username]['lastcheck'] = time()+60;
}

update_option( 'rarst_twitter_user', $cache );
}

if ( false != $display )
echo $cache[$username][$field];
return $cache[$username][$field];
}

anyone help ? thanks.

  • "I have 2 functions about the wp_remote_get" ... update_option( 'rarst_twitter_user', $cache ); ... :) – kaiser Oct 3 '11 at 13:44
1

How does these functions relate to writing file? Do you want to write to file in general or modify functions to accomplish that?

Simple approach - do it with PHP, for example with file_put_contents(). However between different hosting configurations this is not always reliable. Actually workflows in WP make real effort to not write any more files than really necessary - most of things go into database.

Complex and more reliable approach - Filesystem API.

I'd suggest considering database for storage first.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.