SnapShooter Backups Server, Database, Application and Laravel Backups - Get fully protected with SnapShooter

Quick CURL tips for developers

In this tutorial, we will demonstrate two quick tips on using CURL to assist in optimizing application performance.

The curl is shipped with most of the operating system. On MacOS terminal, type curl --help. You should see some output as shown below:

Usage: curl [options...] <url>
 -d, --data <data>   HTTP POST data
 -f, --fail          Fail silently (no output at all) on HTTP errors
 -h, --help <category>  Get help for commands
 -i, --include       Include protocol response headers in the output
 -o, --output <file>  Write to file instead of stdout
 -O, --remote-name   Write output to a file named as the remote file
 -s, --silent        Silent mode
 -T, --upload-file <file>  Transfer local FILE to destination
 -u, --user <user:password>  Server user and password
 -A, --user-agent <name>  Send User-Agent <name> to server
 -v, --verbose       Make the operation more talkative
 -V, --version       Show version number and quit

This is not the full help, this menu is stripped into categories.
Use "--help category" to get an overview of all categories.
For all options use the manual or "--help all".

Measure response time

The first thing in improving response time is to measure response time. So that we can implement the fix and benchmark again.

There are a lot of tools that can help us do that. But CURL is probably much handier.

To measure the response time of a site, simply run:

curl -o /dev/null -s -w 'Establish Connection: %{time_connect}s\nTTFB: %{time_starttransfer}s\nTotal: %{time_total}s\n' google.com

If you run the command above, you should see similar output as shown below:

Establish Connection: 4.512387s
TTFB: 4.726515s
Total: 4.726646s

Replace google.com with your own site to measure your site's response time.

Check HTTP response header

To verify the server side's cache implementation, the common way is to check HTTP response header. We can check via other tools like browser developer console, or API testing tool, and so on.

With CURL, we can do it simply via a command:

curl -sD - -o /dev/null google.com

You should see some similar output as shown below:

HTTP/1.1 301 Moved Permanently
Location: http://www.google.com/
Content-Type: text/html; charset=UTF-8
Date: Fri, 31 Dec 2021 03:07:11 GMT
Expires: Sun, 30 Jan 2022 03:07:11 GMT
Cache-Control: public, max-age=2592000
Server: gws
Content-Length: 219
X-XSS-Protection: 0
X-Frame-Options: SAMEORIGIN

Replace google.com with your own testing URL to find out the response header.

End

Hope you find this tutorial useful!