Jump to content

Changing script to use curl, or any other way to do the following if possible!


loco41211

Recommended Posts

Hello, I am trying to make a php script to fetch the simple cumulative-stats uploadedBytes and downloadedBytes and to add them together. The fetch is done via rpc on transmission (a torrent client).

 

At the current step I have come across a 409 error. When trying it in command line on the server using ssh I get the following output:

http://locotest2.co.cc/a.html

 

I asked on irc but nobody seems to be in the mood to help with this. The rpc specs I was given to use with my script are at 4.2 here:

http://trac.transmissionbt.com/browser/trunk/doc/rpc-spec.txt

 

A guy gave me this pastie on the transmission channel to edit for my own needs:

http://pastie.org/338555

 

I have made a few changes but I need to add a header as per the response I get from curl (see the a.html link above).

 

Here is my current script:

<?

function do_post_request($url, $data)
{
$params = array(
        "http" => array(
            "method" => "POST",
            "content" => $data
         )
    );
print_r($params);die;
    $ctx = stream_context_create($params);

file_get_contents($url);
die ($fp);


    if (!$fp) {
        throw new Exception("Problem with $url, $php_errormsg");
    }

    $response = @stream_get_contents($fp);
    if ($response === false) {
        throw new Exception("Problem reading data from $url, $php_errormsg");
    }

    return $response;
}

/* Construct the request array */
$request = array(
    "method" => "session-stats",
    "X-Transmission-Session-Id" => "6YNbfQSfeewqGnoXwNSlDQVcosRS5ooRgq6yAIwc6C9CFlMF",
    "arguments" => array(
    )
);

/* Do the actual request, decode the reply JSON string into a PHP object */
try {
        $reply = die(do_post_request("http://localhost:9091/transmission/rpc", json_encode($request)));
} catch (Exception $e) {
        exit();
}

/* The reply contains a list 'torrents' of objects with our requested fields */

if ($reply->arguments["cumulative-stats"]->uploadedBytes + $reply->arguments["cumulative-stats"]->downloadedBytes > 6*1024*1024*1024) { /* response triggered command here */  } 

?>

 

Can someone help me get this working? I'm logged on irc.freenode.net with the username loco if its easier to go through it there. I am extremely grateful for any help on this. Especially if someone can rewrite this for me!

 

Awaiting your answers,

loco

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.