ahmed
ahmed

Reputation: 14666

Can I include CURL library in my PHP script as a class

I want to use CURL library but I don't want to install it in a hard way

I just want to do something like this

require_once('curl.php');

I am not sure if this possible or not? and where can I found this CURL class?

thanks

Upvotes: 1

Views: 10239

Answers (4)

rubo77
rubo77

Reputation: 20865

There is also a standalone version called "MyCurl", that you can include without installation:

http://www.phpclasses.org/package/3588-PHP-Pure-PHP-implementation-of-the-cURL-library.html

i used it in my project and it worked fine with http-requests.

This class provides an alternative implementation of the cURL extension functions in pure PHP.

It automatically detects whether the cURL library is available. If it is not available, it defines several functions with the same names of the cURL extension that use the class to emulate part the original functionality.

Currently it implements the functions: curl_init, curl_exec, curl_setopt and curl_close. Several of the most important options can be set with the curl_setopt function.

although it has some small bugs, it works aftre fixing this:

  1. the example doesent work out of the box, cause the domain lazywebmastertools.com is not reacheable
  2. there is an @ needed if the requested domain doesent end with "/":

    return "/".@$tmp[1];

  3. if you dont use a proxy, you have to set

    if (isset($this->proxy) and $this->proxy["host"])...

  4. if (isset( $this->headers["location"]) and $this->headers["location"] > "") {...

the drawback is, that this class doesent support https. there you would need the Snoopy Class: https://stackoverflow.com/a/1154247/1069083

Upvotes: 1

SchizoDuckie
SchizoDuckie

Reputation: 9401

There is a Pure PHP Curl implementation called libCurlEmu

Just bear in mind: you should only use this kind of stuff as a last resort if you can't get the extensions to work.

Upvotes: 1

dicroce
dicroce

Reputation: 46800

You're copy of PHP is either going to have to have been built with Curl, or dynamically load it in (because Curl is not originally written in PHP, it's a C library).

Create a simple script that calls phpinfo(). If curl was built in, it should show up on this page.

phpinfo();

Upvotes: 3

Cody Caughlan
Cody Caughlan

Reputation: 32758

PHP requires that its built with the cURL library, see:

http://www.php.net/manual/en/curl.installation.php

So you would install libcurl-devel for your system and then compile PHP with

--with-curl

And maybe

--with-curl=/path/to

If you installed it in a non-standard location.

Upvotes: 7

Related Questions