Yii Framework Forum: Request for Comments: CHttpClient - Yii Framework Forum

Jump to content

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

Request for Comments: CHttpClient A http client for Yii 1.1.x Rate Topic: ***** 1 Votes

#21 User is offline   acorncom 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 99
  • Joined: 25-February 11
  • Location:CO, USA

Posted 07 March 2013 - 12:47 PM

View PostDa:Sourcerer, on 07 March 2013 - 12:13 PM, said:

And yes, I'm a bit selfish because I like the intellectual challenge of this.


Understood :-) However, do you think it's a good use of your time? You've been helping out with a lot of other areas of Yii that have also needed attention (I've been watching the pull requests and issues on Github coming through). Would the Yii community be better served if you used the effort you might pore into maintaining / extending this library on other things?
0

#22 User is offline   Da:Sourcerer 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,222
  • Joined: 30-March 11
  • Location:Berlin, Germany

Posted 07 March 2013 - 01:05 PM

Well, that's debatable. I've already spent quite an amount of time into the first attempt at this and the rewrite is taking up more time than I ever imagined. However, I still feel it is worth the effort. I see myself using this component (quite a way to pat my own back :lol: ) and if others take advantage of it: All the better. And to be honest: atm I'm mostly out of ideas what else I could provide to the core. I've got some code cooking that would be good as separate extension, but very little that could or even should find its way into the framework itself.
programmer /ˈprəʊgramə/, noun: a device that converts ►coffee into ►code
0

#23 User is offline   yJeroen 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 94
  • Joined: 06-September 11
  • Location:The Netherlands

Posted 12 April 2013 - 09:14 AM

Hi Da:Sourcerer,

I was wondering.. Can you point out some advantages/disadvantages when you compare your chttpclient to ehttpclient?

The main difference I see is that that extension has multiple possible connectors, while you only use streams. Is there any reason for that?

Thanks :)
0

#24 User is offline   Da:Sourcerer 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,222
  • Joined: 30-March 11
  • Location:Berlin, Germany

Posted 15 April 2013 - 09:43 AM

Well, let me start off with saying that most development on CHttpClient is now happening in the new CHttpClient-ng branch. A lot is still happening outside of git for various reasons.

As for your questions: EHttpClient is pretty much a one-shot object. You create it, fire off your http request and need to create a new one if you would want to issue another http request. CHttpClient is different in that regard as it registers as an actual stateless application component, preparing request objects and delegating them to a configured connector. The connectors now are pretty much the same thing as adapters in EHttpClient/Zend_Http_Client or request processors in Habari's http infrastructure. They are held responsible for pushing the prepared request over the wire and parsing the http response into an according object. The idea of having several connectors is to provide a connector using PHP's stream sockets, thus being able to work in pretty much every environment, and some others using cURL or pecl::http, providing faster message parsing.

The actual advantages are now a bit abstract. It is definitely easier to set up a set of headers sent among all outgoing requests, as you only need to configure the CHttpClient component accordingly. Caching and cookie management integrate nicer into Yii. I've also put some considerable effort into method chaining, so in the end you will be able to do something like this:
echo Yii::app()->http->get('http://example.org')-> //prepare the request
                       disableCaching()->          //don't send caching http headers
                       addHeader('DNT','1')->      //send the do-not-track header along
                       send()->                    //send the request out
                       body                        //print out the response's body


Oh, and about Guzzle and cURL: I found out that Guzzle indeed uses cURL unconditionally for all network operations. It seems to me the original author wanted to avoid dealing with all the gory details of socket programming. Frankly, I quite understand that. E.g. handling 100/Continue responses with stream_select() is a bit tricky :P
programmer /ˈprəʊgramə/, noun: a device that converts ►coffee into ►code
1

#25 User is offline   Da:Sourcerer 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,222
  • Joined: 30-March 11
  • Location:Berlin, Germany

Posted 02 November 2013 - 06:35 AM

I've been in a coding-rush during the last days. Only to be stopped by the following unrecoverable error:

Quote

stream_filter_append(): cannot use a user-space filter with a persistent stream

If I wouldn't know better, I'd say PHP just flicked me off :blink:
programmer /ˈprəʊgramə/, noun: a device that converts ►coffee into ►code
0

#26 User is offline   Da:Sourcerer 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,222
  • Joined: 30-March 11
  • Location:Berlin, Germany

Posted 26 November 2013 - 09:25 AM

Getting more and more usable. I just managed to crawl the Wacken Open-Air forum with this code:
$request=Yii::app()->http->get('http://woafor.wacken.com/showthread.php');
for($t=1; $t<=1024; ++$t)
{
	$request->url->params['t']=$t;
	echo "$t\t";
	$response=$request->send();
	if($response->isSuccessful())
	{
		preg_match('/<title>(.+)<\/title>/',$response->body,$matches);
		$title=trim(strip_tags($matches[1]));
		echo $title.PHP_EOL;
	}
	else
		echo ">> {$response->status} {$response->message}".PHP_EOL;
}

Turns out their forum isn't very resty and returns 200/Ok for deleted or inexsitant threads :lol:
programmer /ˈprəʊgramə/, noun: a device that converts ►coffee into ►code
0

Share this topic:


  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users