Subject: Update on the PHP for Google App Engine Limited Preview program
I recently received this email from the App Engine team. It’s great timing, since I’m planning on moving more PHP applications to App Engine.
Tips, tricks, and thoughts about Google, AdWords, Google Cloud Platform, and all its subsidiaries. Not affiliated with or sponsored by Google.
Subject: Update on the PHP for Google App Engine Limited Preview program
I recently received this email from the App Engine team. It’s great timing, since I’m planning on moving more PHP applications to App Engine.
The following is an example of a request originating from a cron:
It’s easy to tell this request originates from cron because (1) the originating IP is 0.1.0.1 (which is a reserved IP; cron requests come only from that address) and (2) the queue name is listed as cron .
Sender Policy Framework (SPF) is a way to validate outgoing mail; it essentially allows a domain to say, “only these named servers are allowed to send mail under my name; any other servers attempting to do so may be malicious or may be sending spam.” If you send mail from your domain, it’s important to set SPF rules so receiving domains know that your mail is valid and isn’t spam.
To create your SPF record, visit the SPF website and figure out the appropriate SPF record for your domain. Then place it as a TXT record in your domain’s DNS.
As an example, my domain sends no mail so the appropriate SPF record is:
v=spf1 -all
If you have NameCheap as your domain registrar, here’s how to set an SPF record. First, log in and click the link All Host Records:
Put in the following settings:
Host Name: @
IP Address: v=spf1 -all
Record Type: TXT
TTL: 1800
Here’s how it looks like on the administration console:
If you use a different domain registrar there should be similar options. If not, contact your registrar for the appropriate steps to take.
When I need to measure elapsed time (for example, timing how long an API call takes) I prefer to use System.nanoTime() instead of using the usual method of (new Date()).getTime().
The key idea to remember is that nanoTime() doesn’t return a timestamp – it represents a measurement of time from some arbitrary point (so for example nanoTime() could return a negative figure). This helps when writing self-documenting code: a variable storing a nanoTime() value can only be used for elapsed time comparisons, not timestamp recording.
Here’s an example of measuring elapsed time with System.nanoTime(). First, record the start time:
/**
* Records the start time
* using System.nanoTime()
*/
Long start_time;
//Record the start time.
start_time = System.nanoTime();
Insert some time-consuming operation here, or another long-running call. Place this code where you want to end the timer:
//Calculate how long we've been running in nanoseconds.
Long diff_time = System.nanoTime() - start_time;
The variable diff_time stores the number of nanoseconds that has elapsed during the timer. Now suppose you wanted to throw an exception if the timer took more than 30 seconds (30 billion nanoseconds); here’s the example code:
//We set the maximum time in nanoseconds, multiplied by milliseconds,
//multiplied by seconds.
Long MAXIMUM_TIME_OPEN = new Long(1000000L * 1000 * 30);
//If the runtime of this operation is longer than the time we've set,
//throw an Exception.
if (diff_time > MAXIMUM_TIME_OPEN) {
throw new IOException("Timeout has been exceeded.");
}
To keep the code easy to understand, we’re showing how the maximum time amount is computed: there are 1 million (1,000,000) nanoseconds in a millisecond, multiplied by 1 thousand milliseconds in a second (1,000), multiplied by 30 seconds.
A few weeks ago I presented screenshots of a free tier application handling over 52,000 requests per day without breaking a sweat. That same application recently broke 225,000 requests per day. Here’s how the app console looked like:
Here are the error screens. Notice there were only 2 errors out of 225,000+ requests:
First, go to the Google Cloud console at https://cloud.google.com/console . You’ll see the following screen. Click on a project or create a new one:
Click on the Compute Engine link on the next screen:
Press the Networks link on the left hand side navigation bar:
You’ll see the button New static IP within the Networks screen:
Name your new IP address, set a description (optional), and set the region where your IP address is located in. You can optionally also attach your new IP to a machine, if you have one running.
After you click the Create button, Compute Engine will need a few seconds to allocate a new IP address:
Once the allocation is complete, your new IP address will be listed in the Networks screen: