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
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.
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();
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.
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:
the example doesent work out of the box, cause the domain lazywebmastertools.com is not reacheable
there is an # needed if the requested domain doesent end with "/":
return "/".#$tmp[1];
if you dont use a proxy, you have to set
if (isset($this->proxy) and $this->proxy["host"])...
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
Related
Are there Libraries which are in every present PHP installation?
An Example:
I'm using cURL in a PHP Script, does it run on every PHP installation?
Libraries like cURL aren't in a default PHP installation. Though most hosts do carry a default set of extensions which have been widely used, which usually include cURL.
PHP has a page on which it's built-in functions which will most likely explain this further: http://nl3.php.net/manual/en/functions.internal.php
There's also a page with function references to find the most used libraries that can be installed using PEAR: http://nl3.php.net/manual/en/funcref.php
I'm trying to make a JSON call library. It has the following features.
be able to customize the header
be able to POST any data to server(including form-encoding (a=1&b=2&c=3) and JSON data chunk)
parse the response and return as a JSON object
I searched in other questions and found that there are only two answers.
use file_get_contents(). This way is pretty simple and easy to use; however, you cannot do anything more than get the content -- you cannot add headers, cannot use POST. But it is usually supported by all servers.
use curl. This way seems powerful and you can do nearly everything with it. The disadvantage is that you have to install libcurl and php-curl support on your server, which means you may not use it on servers that have no curl installed.
So, if I want to develop a common library that can be used on most server, is curl a good choice?
Is there any other ways to do this?
In a short word, I'm looking for a PHP version of urllib2 in python - easy to use, powerful, and reliable.
You have two options: curl and HTTP stream context options. Both can accomplish what you have described; curl might not be installed everywhere, while stream contexts are a core feature and are always available.
Actually, you can also implement your library using sockets, which would be more work but will probably allow you greater control if you need to do weirder things with your requests.
As i know, curl is included in mostly on many server, since it supported from 4.0.2 PHP version natively.
Also there is a native php function header, which customizes your response's headers by simply using like this -> header('location: index.php'), header('cache-control: ok') and so on. You can view Network Functions section on php.net
I searched over the Internet several documentation about how to create PHP extensions, but unfortunately, there is nothing about linking to another extensions (and making a requirement for having that extension loaded prior to the new it is being created).
I guess I could simply #include necessary header files into my source code, but not sure about linking.
As an example, and to play with extension creation, the first I want to create is a solution I implemented to allow namespaces in memcached github but wanted to know how to use other extensions' code from my custom extension one for other usages as well.
I'm not sure how to reply to the thread with StormByte, but it sounds like you need to do some load balancing or caching, not extending PHP.
If you really want to do this at the code level, you could use exec() to call a Python script, which gets compiled into byte code automatically.
I need to call a dll that returns a string using PHP.
What would be the best possible way to achieve this?
Build a PHP extension that wraps the DLL or create a wrapper (in any language) that can be accessed via shell with exec.
This is not possible using native PHP.
I would look into running an operating system level function to do this using exec(), like for example rundll.exe (for some kinds of DLLs).
If rundll can't do it (it has something to do with managed and unmanaged DLLs, I don't know what that means), the easiest way may be writing a wrapper application that imports the DLL, performs the necessary actions, and outputs the result.
I am trying to proxy through php for a JS RSS feed. The company I am doing this for may or may not want cURL installed. If that is the case I may need some sort of library that can simply be included in php rather than go through apache and all of that. Is there a library that can handle something like that? What other options do I have in this case?
Thanks!
Zend_HTTP provides a wrapper for fopen, file_get_contents and CURL out of the box, it makes it much more simpler to store / read cookies, make POST requests and so on.
wget, fopen, and file_get_contents are other options you can use to use for a proxy.