Yii Framework Forum: Curl Wrapper - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Curl Wrapper Rate Topic: -----

#1 User is offline   hackerone 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 18-November 11

Posted 04 October 2012 - 11:06 AM

Hi guys,

just made this simple Curl wrapper for yii. i've seen one in extensions earlier, but wanted one which is light weight and simpler to use for my project, so made this one.

it's on github

hackerone/curl

thanks for your feedbacks in advance :)
1

#2 User is offline   Rodrigo Coelho 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 645
  • Joined: 05-August 10
  • Location:Rio de Janeiro, Brazil

Posted 04 October 2012 - 11:35 AM

Seems very easy to use. Thanks for sharing it!
Rodrigo Coelho


Check my extension
giix: a code generator for Yii. Posted Image


The complete beginner's study guide for the Yii Framework
0

#3 User is offline   AustinGeek 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 146
  • Joined: 22-September 12

Posted 15 January 2013 - 02:43 PM

I seem to be having trouble with a simple example.

I get
"Use of undefined constant CURLOPT_RETURNTRANSFER - assumed 'CURLOPT_RETURNTRANSFER' "

when executing

$output = Yii::app()->curl->init();

I looked at the package, it seems pretty simple. I can execute curl calls from the command line but it seems
that my package is not configured or something of the sort.

My main.php in config is set like this. Not sure what options I need to set...the init() should be setting them.
'curl' => array(
			'class' => 'ext.Curl',
			//'options' => array(/.. additional curl options ../)
		);


The examples with the yii-curl wrapper were pretty simplistic so maybe I misinterpreted them.
0

#4 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 15 January 2013 - 03:37 PM

I think your PHP instance doesn't have CURL support.
Is it listed in modules?

If you run phpinfo() on your server you should see if it does or not.
"Less noise - more signal"
0

#5 User is offline   AustinGeek 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 146
  • Joined: 22-September 12

Posted 15 January 2013 - 04:06 PM

You are probably correct.

I'm on Ubuntu 12.04LTS / NGINX / PHP5 / MySQL

I did do an install php5-curl and it seemed to work cambe back with setting up php5-curl (so it wasn't installed before)
I have been using curl from the command line recently in preparation for this project.

I don't see it when I issue phpinfo()...it comes back with alot of stuff, would curl be in it's own block
right after "core" parameters?
0

#6 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 15 January 2013 - 04:25 PM

It should be in it's own block. :)

You probably need to enable the module in php.ini.
"Less noise - more signal"
0

#7 User is offline   AustinGeek 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 146
  • Joined: 22-September 12

Posted 15 January 2013 - 04:32 PM

View Postjacmoe, on 15 January 2013 - 04:25 PM, said:

It should be in it's own block. :)

You probably need to enable the module in php.ini.


I am looking at php.ini but don't see anything about curl...
0

#8 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 15 January 2013 - 05:54 PM

php_curl, I guess.
"Less noise - more signal"
0

#9 User is offline   AustinGeek 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 146
  • Joined: 22-September 12

Posted 17 January 2013 - 02:02 AM

View Postjacmoe, on 15 January 2013 - 05:54 PM, said:

php_curl, I guess.


Jacmoe,
You were correct.

php_curl needed to be installed, it gave me a bit of difficulty but I think the problem was having to reboot the server
before the module showed up...Maybe I just needed to restart the webserver...

Works like a charm, thanks again for your help!
0

#10 User is offline   AustinGeek 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 146
  • Joined: 22-September 12

Posted 24 January 2013 - 11:30 AM

How to use cookies and send info on the curl command?

I was trying to use this extension. I created a json string and posted it to authorize a connection. That worked.

I need to send a token with the GET command but not sure how to do it. curl -H "Authorization:12132455dae234234" 'http://api.site.com/getdata'

I could also use a cookie but not sure how to set it up. curl -b cookie 'http://api.site.com/getdata' ;

The way parameters work in the get() they are a suffix to the url. get(url,params)

Any suggestions? Thanks !

This worked for me....
$auth = array('Authorization:'.$token);
$jsonObject = Yii::app()->curl->setOption(CURLOPT_HTTPHEADER, $auth)->get($url);

0

Share this topic:


Page 1 of 1
  • 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