Posts Tagged ‘curl’

installing EasyPHP

June 27, 2016 Leave a comment

I wanted to contribute to a PHP project but under Manjaro I couldn’t test it locally. I got a “Fatal error: Call to undefined function curl_init()” message that I didn’t manage to resolve, though the line “” was present in my php.ini :(

After a few hours of trial and error, I decided to develop this project under Windows. I have Windows in VirtualBox, I put the PHP project in a shared folder, so my idea was to edit the source under Linux and visualize the result under Windows.

I chose EasyPHP and installed the latest EasyPHP Devserver that provides a complete development environment.

When I opened the project I got the same error since curl was not enabled by default. On the dashboard I could edit the php.ini file and uncommented the line “extension=php_curl.dll“. However, after restarting the webserver I got another error: libssh2 is missing. I found the solution here (ken’s comment):

"I had to also also copy libssh2.dll into my Apache24 folder 
for this to work with my PHP 5.6.2 installation. So altogether 
I had to do the following:

Move to Windows\system32 folder:
libssh2.dll, php_curl.dll, ssleay32.dll, libeay32.dll

Move to Apache24\bin folder

Uncomment extension=php_curl.dll"

I found all these files in the install folder of EasyPHP. There are two versions of each, one in a “…vc11…” folder, while the other one in a “…vc14…” folder. I worked under PHP 5.6 so I copied the vc11 versions of each file mentioned above.

After this Apache restarted without any error.

Categories: php, windows Tags: , , ,

Google’s URL shortener

June 25, 2013 Leave a comment

You want to shorten a long URL from the command line / from a script.

There are lots of URL shorteners. With the Google URL shortener you can do it like this:

curl -H 'Content-Type: application/json' -d '{"longUrl": ""}'

Sample output:

    "kind": "urlshortener#url",
    "id": "",
    "longUrl": ""

Let’s do it in Python using the requests module:

import requests
import json

url = ""
data = {"longUrl": ""}
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
r =, data=json.dumps(data), headers=headers)
print r.text
print 'Short URL:', r.json()["id"]


Test if a webpage exists

January 24, 2012 Leave a comment
curl --head
# or, the same:
curl -I

Sample output:

HTTP/1.1 301 Moved Permanently
Content-Type: text/html; charset=UTF-8
Date: Tue, 24 Jan 2012 20:22:14 GMT
Expires: Thu, 23 Feb 2012 20:22:14 GMT
Cache-Control: public, max-age=2592000
Server: gws
Content-Length: 219
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN

For a pure Python solution, check out this post.

This tip is from here.

Categories: bash, python Tags: ,

Download a webpage and print it to the standard output

August 10, 2011 Leave a comment

You want to download a webpage and print its content to the standard output. For instance you want to push it through a pipe for further processing.

The easiest way is to use “curl” since by default it prints the downloaded content to the stdout:

curl | less

You might want to add the switch “-s” to make curl silent, i.e. hide the progress bar.

With “wget” it’s a bit more complicated:

wget -qO- | less

If you want to add syntax highlighting to less, see this post.

Redirecting wget to STDOUT – now with Syntax Highlighting