Do RPC calls to transmission-daemon through php

Discussion of Transmission that doesn't fit in the other categories
deadeyes
Posts: 20
Joined: Wed Jun 16, 2010 7:02 am

Do RPC calls to transmission-daemon through php

Post by deadeyes »

Hi all,

I was wondering what library/functions/... I should need to control transmission-daemon through rpc using PHP.

Would this work? http://jsonrpcphp.org/?page=example&lang=en

Or do I need the included functions in php, ...?

I looked in the docs: https://trac.transmissionbt.com/browser ... c-spec.txt
However I do not get a clue how to accomplish this in php.
Do I need to create the array literally as listed in those docs and sent it as post data?
Is there some api to connect to rpc in php (independent from transmission-daemon?).
Or is the implementation of those rpc calls specific to transmission-daemon and should I write custom code to communicate through rpc with transmission-daemon?

Maybe someone has an example on how to do this?

Thanks in advance.
brycec
Posts: 9
Joined: Sun Jun 27, 2010 12:54 pm

Re: Do RPC calls to transmission-daemon through php

Post by brycec »

Hi deadeyes!
As it just so happens, I started work tonight on a PHP Class based loosely on the JSON-RPC project you linked to. I searched for something, anything, but came up with nil so I am writing my own (to be used in another project).
I'll be sure to post another reply when I have a release ready.

EDIT:
Oh I did find this, though its use/adaptation didn't quite fit my needs. http://hype-o-thetic.com/2009/11/07/a-p ... -json-rpc/
brycec
Posts: 9
Joined: Sun Jun 27, 2010 12:54 pm

Re: Do RPC calls to transmission-daemon through php

Post by brycec »

I've posted version 0.1 of my PHP library (it's a class, if you want to be technical) at
http://www.cobryce.com/transmission-rpc-php-library

I'd like to emphasize that it's still pretty young, and it's not been extensively (or barely) tested. It's working for my project, that's all I can say.
I'm going to keep working on it as I have time, and as my other project necessitates. When it's reached 1.0, I'll go ahead and post an announcement in the forums.

Feel free to send any feedback, ideas, suggestions, etc. You can also find me on IRC - brycec @ FreeNode, SlashNet, and Foonetic.
deadeyes
Posts: 20
Joined: Wed Jun 16, 2010 7:02 am

Re: Do RPC calls to transmission-daemon through php

Post by deadeyes »

Great hearing you are developing code for this.
I had programmed a few functions to do basic calls.
I will look into your code probably this evening or tomorrow.

Keep coding ;)
deadeyes
Posts: 20
Joined: Wed Jun 16, 2010 7:02 am

Re: Do RPC calls to transmission-daemon through php

Post by deadeyes »

I just took a fast look.
I was also thinking about using jsonrpc.
However I implemented this using libcurl.
It is rather easy and does not have jsonrpc as a dependency (and I don't know what dependencies jsonrpc has).

I will later look into it again... if it has evolved and if it can help me for my project.

THanks again for the efforts you are doing.
johan.adriaans
Posts: 10
Joined: Wed Jun 30, 2010 10:56 pm

Re: Do RPC calls to transmission-daemon through php

Post by johan.adriaans »

Lol, I thought there was nothing definitive out there so i built this class. Should do better research next time ;)
http://code.google.com/p/php-transmissi ... loads/list
deadeyes
Posts: 20
Joined: Wed Jun 16, 2010 7:02 am

Re: Do RPC calls to transmission-daemon through php

Post by deadeyes »

It is communicating using curl with the transmission daemon, just like my coding, but I have to say it is better then mine. :) Thanks for sharing with us!
brycec
Posts: 9
Joined: Sun Jun 27, 2010 12:54 pm

Re: Do RPC calls to transmission-daemon through php

Post by brycec »

Haha so we all wrote our own at about the same time... What are the odds?

@deadeyes
Just to clarify - The class I wrote has no dependency on JSON-RPC. It also has no dependency on cURL - the platform I'm using it in doesn't have the PHP cURL extension, so I stuck with the basics. (I'm not knocking cURL or libcurl - I love them both dearly and use both extensively whenever possible. This wasn't one of those times)

@johan.adriaans
Very nice, I like it. And if it didn't require cURL I'd consider using it instead. One suggestion - I would recommend implementing torrent-add's "metainfo" argument method as well. Assume you're processing a torrent that is local/on-disk, or attached to an e-mail (as I am) - the 'file' method won't cut it unless the script first uploaded the extracted torrent to a server Transmission could connect to as well. Or you can simply bass the raw torrent (base64_encode()'d) to Transmission.
One other recommendation - the class should throw Exceptions for the parent program to catch, or at least return an error code. die()ing inside a class is a very bad idea, it prevents the parent script from cleaning up (connections, variables, open files, etc) or performing any error-handling/processing (notify the user, email, or even re-trying).

Keep up the good work guys.
johan.adriaans
Posts: 10
Joined: Wed Jun 30, 2010 10:56 pm

Re: Do RPC calls to transmission-daemon through php

Post by johan.adriaans »

@brycec Lol, yeah, unbelievable :)

The torrent-add metadata is handled by the $extra_options argument, so its in there, just a bit hidden ;)
I know the die() is bad practice; as i am using it as a shell script the die() is a more practical way of displaying whats wrong. I didn't feel the script using the class should handle the exceptions. And without them handling it the users gets ugly uncaught exceptions. It was a first-version-decision and now that you mention it, it would be better to make it optional ;)

Curl might be a bad decision to, i didn't get the session_id working properly with php native streams. :oops:

This might be a bold move.. But would you like to join forces? It think its better to create 1 very good class than to go our separate ways. We take your exception handling and php streams and my test/examples etc.

Let me know what you think, it would be a shame to let the users choose between 2 good things when there could be one better thing.
brycec
Posts: 9
Joined: Sun Jun 27, 2010 12:54 pm

Re: Do RPC calls to transmission-daemon through php

Post by brycec »

@johan.adriaans
Sure, I'm open to that. Let's PM on the details and such.
deadeyes
Posts: 20
Joined: Wed Jun 16, 2010 7:02 am

Re: Do RPC calls to transmission-daemon through php

Post by deadeyes »

@brycec: I misunderstood that you use jsonrpc as that is in your title and also mentioned in the first post:)

I have to say I am more fond of using curl. As it eases up things.
So for me johan.adriaans seems most suitable for me.

One thing I changed was using json_decode($result, true) instead of only using one argument.
This returns a fully nested array instead of objects in an array.

Great work guys :)

Please keep everyone updated.

One more thing.. it would be great to have a constructor that enables you to set the host to connect to, credentials, ...
But this is rather simple.
brycec
Posts: 9
Joined: Sun Jun 27, 2010 12:54 pm

Re: Do RPC calls to transmission-daemon through php

Post by brycec »

@deadeyes,
No problem - I'm merging Johan's and my efforts right now, and I've included the constructor.
A note - my original class did use json_decode(..., true). Maybe you were addressing Johan's? Regardless, that has been copied over as well.
I'm looking forward to posting a followup later today with the new release of our merged efforts. (Of course Johan will have his own critiques and edits to make... and there will be more cleanup after that)
johan.adriaans
Posts: 10
Joined: Wed Jun 30, 2010 10:56 pm

Re: Do RPC calls to transmission-daemon through php

Post by johan.adriaans »

yeah im a very precise programmer..
Looking forward to your first merge! i think ill have some spare time to clean it up ;) And maybe some more examples?
brycec
Posts: 9
Joined: Sun Jun 27, 2010 12:54 pm

Re: Do RPC calls to transmission-daemon through php

Post by brycec »

Thanks Johan - I haven't had time until this morning, so I'm furiously merging away... (among other things)
I agree, more examples would be good. Especially if they could illustrate Exception handling :wink:
Once I get this merge done, I have a bunch of work to do on my "other project" (one of many, but I'm referring to my project that uses the TransmissionRPC class) to implement the revised class and a whole bunch of ideas I've had to stockpile because I'm focused on this.
cheers!
brycec
Posts: 9
Joined: Sun Jun 27, 2010 12:54 pm

Re: Do RPC calls to transmission-daemon through php

Post by brycec »

@deadeyes
I've uploaded my merged version to http://code.google.com/p/php-transmission-class/
Give it a shot? I'm sure Johan will be making edits soon.

Todo: More examples. Documentation (any at all).
Post Reply