Title:
UrlFetchApp.fetch() intermittently times out when accessing my website, while the same URL sometimes returns HTTP 200
Description
Hello Google Apps Script Community,
I am experiencing an intermittent timeout issue when using Google Apps Script’s UrlFetchApp.fetch() to access my website:
Website: https://quoteplan.net
Test URL: https://quoteplan.net/test.php
My website is hosted with InMotion Hosting and uses PHP/CodeIgniter.
1. Problem
When I call my website using UrlFetchApp.fetch(), some requests succeed while others fail with the following error:
Exception: Timeout: https://quoteplan.net/test.php?diagnostic_id=...
The failed requests consistently time out after approximately 4 seconds.
However, requests to the exact same URL sometimes succeed in approximately 120–286 milliseconds.
2. Test environment
To rule out application-level issues, I created a simple test.php file containing only:
<?php
echo "QuotePlan PHP is working!";
This file opens normally in my web browser.
However, requests from Google Apps Script to this file intermittently time out.
I also tested the website’s root URL and robots.txt, and observed intermittent failures with those URLs as well.
3. Test results
I ran 30 consecutive requests from Google Apps Script to the same test URL.
-
Total requests: 30
-
Successful requests (HTTP 200): 18
-
Failed requests (timeout): 12
-
Successful response times: approximately 120 ms to 2.34 seconds
-
Failed request times: approximately 4.06 to 4.09 seconds
No changes were made to the test PHP file between requests.
4. Sample Apps Script code
function testQuotePlan() {
const url = "https://quoteplan.net/test.php";
const start = Date.now();
try {
const response = UrlFetchApp.fetch(url, {
method: "get",
muteHttpExceptions: true
});
console.log(JSON.stringify({
status: response.getResponseCode(),
durationMs: Date.now() - start,
body: response.getContentText()
}));
} catch (error) {
console.log(JSON.stringify({
durationMs: Date.now() - start,
error: String(error)
}));
}
}
5. Hosting investigation
I contacted my hosting provider and reviewed the Apache access logs.
Some failed requests do not appear in the Apache access logs. My hosting provider is being asked to investigate firewall and network-level connectivity.
I understand that the missing Apache log entries do not necessarily prove that the requests never reached the server.
6. Questions
-
Can Google Apps Script’s
UrlFetchApp.fetch()experience intermittent connection or timeout issues when communicating with an external HTTPS website? -
Is there a known issue with Google’s URL Fetch infrastructure that could explain a pattern where some requests succeed quickly while others time out after approximately 4 seconds?
-
Could this behavior be related to Google’s outbound IP ranges, DNS resolution, IPv4/IPv6 connectivity, TCP connections, or TLS negotiation?
-
Is there a recommended way to diagnose whether the timeout occurs in Google’s URL Fetch infrastructure, along the network path, or on the destination server?
-
Is there any additional diagnostic information I should collect to help identify the cause?
I would appreciate any suggestions or guidance on how to isolate the problem.
Thank you.