I tried the AsObjC version. It is only 1.5 times faster:
use AppleScript version "2.5"
use scripting additions
use framework "Foundation"
use framework "AppKit"
property |NSURL| : a reference to current application's |NSURL|
property NSURLRequest : a reference to current application's NSURLRequest
property NSURLConnection : a reference to current application's NSURLConnection
property theServers : {"https://www.macscripter.net/viewforum.php?id=3", "https://www.macscripter.net/viewforum.php?id=4", "https://www.macscripter.net/viewforum.php?id=5", "https://www.macscripter.net/viewforum.php?id=6", "https://www.macscripter.net/viewforum.php?id=7", "https://www.macscripter.net/viewforum.php?id=8", "https://www.macscripter.net/viewforum.php?id=9", "https://www.macscripter.net/viewforum.php?id=10", "https://www.macscripter.net/viewforum.php?id=11", "https://www.macscripter.net/viewforum.php?id=12", "https://www.macscripter.net/viewforum.php?id=13", "https://www.macscripter.net/viewforum.php?id=14", "https://www.macscripter.net/viewforum.php?id=15", "https://www.macscripter.net/viewforum.php?id=16", "https://www.macscripter.net/viewforum.php?id=17", "https://www.macscripter.net/viewforum.php?id=18", "https://www.macscripter.net/viewforum.php?id=19", "https://www.macscripter.net/viewforum.php?id=20", "https://www.macscripter.net/viewforum.php?id=21", "https://www.macscripter.net/viewforum.php?id=22", "https://www.macscripter.net/viewforum.php?id=23", "https://www.macscripter.net/viewforum.php?id=24", "https://www.macscripter.net/viewforum.php?id=25", "https://www.macscripter.net/viewforum.php?id=26", "https://www.macscripter.net/viewforum.php?id=27", "https://www.macscripter.net/viewforum.php?id=28", "https://www.macscripter.net/viewforum.php?id=29", "https://www.macscripter.net/viewforum.php?id=30", "https://www.macscripter.net/viewforum.php?id=31", "https://www.macscripter.net/viewforum.php?id=32", "https://www.macscripter.net/viewforum.php?id=33", "https://www.macscripter.net/viewforum.php?id=34", "https://www.macscripter.net/viewforum.php?id=35", "https://www.macscripter.net/viewforum.php?id=36", "https://www.macscripter.net/viewforum.php?id=37", "https://www.macscripter.net/viewforum.php?id=38", "https://www.macscripter.net/viewforum.php?id=39", "https://www.macscripter.net/viewforum.php?id=40", "https://www.macscripter.net/viewforum.php?id=41", "https://www.macscripter.net/viewforum.php?id=42", "https://www.macscripter.net/viewforum.php?id=43", "https://www.macscripter.net/viewforum.php?id=44", "https://www.macscripter.net/viewforum.php?id=45", "https://www.macscripter.net/viewforum.php?id=46", "https://www.macscripter.net/viewforum.php?id=47", "https://www.macscripter.net/viewforum.php?id=48", "https://www.macscripter.net/viewforum.php?id=49", "https://www.macscripter.net/viewforum.php?id=50", "https://www.macscripter.net/viewforum.php?id=51", "https://www.macscripter.net/viewforum.php?id=52", "https://www.macscripter.net/viewforum.php?id=53", "https://www.macscripter.net/viewforum.php?id=54", "https://www.macscripter.net/viewforum.php?id=55", "https://www.macscripter.net/viewforum.php?id=56", "https://www.macscripter.net/viewforum.php?id=57", "https://www.macscripter.net/viewforum.php?id=58", "https://www.macscripter.net/viewforum.php?id=59", "https://www.macscripter.net/viewforum.php?id=60", "https://www.macscripter.net/viewforum.php?id=61", "https://www.macscripter.net/viewforum.php?id=62", "https://www.macscripter.net/viewforum.php?id=63", "https://www.macscripter.net/viewforum.php?id=64", "https://www.macscripter.net/viewforum.php?id=65", "https://www.macscripter.net/viewforum.php?id=66", "https://www.macscripter.net/viewforum.php?id=67", "https://www.macscripter.net/viewforum.php?id=68", "https://www.macscripter.net/viewforum.php?id=69", "https://www.macscripter.net/viewforum.php?id=70", "https://www.macscripter.net/viewforum.php?id=71", "https://www.macscripter.net/viewforum.php?id=72", "https://www.macscripter.net/viewforum.php?id=73", "https://www.macscripter.net/viewforum.php?id=74", "https://www.macscripter.net/viewforum.php?id=75", "https://www.macscripter.net/viewforum.php?id=76", "https://www.macscripter.net/viewforum.php?id=77", "https://www.macscripter.net/viewforum.php?id=78", "https://www.macscripter.net/viewforum.php?id=79", "https://www.macscripter.net/viewforum.php?id=80", "https://www.macscripter.net/viewforum.php?id=81", "https://www.macscripter.net/viewforum.php?id=82", "https://www.macscripter.net/viewforum.php?id=83", "https://www.macscripter.net/viewforum.php?id=84", "https://www.macscripter.net/viewforum.php?id=85", "https://www.macscripter.net/viewforum.php?id=86", "https://www.macscripter.net/viewforum.php?id=87", "https://www.macscripter.net/viewforum.php?id=88", "https://www.macscripter.net/viewforum.php?id=89", "https://www.macscripter.net/viewforum.php?id=90", "https://www.macscripter.net/viewforum.php?id=91", "https://www.macscripter.net/viewforum.php?id=92", "https://www.macscripter.net/viewforum.php?id=93", "https://www.macscripter.net/viewforum.php?id=94", "https://www.macscripter.net/viewforum.php?id=95", "https://www.macscripter.net/viewforum.php?id=96", "https://www.macscripter.net/viewforum.php?id=97", "https://www.macscripter.net/viewforum.php?id=98"}
set connectedServers to {}
repeat with aServer in theServers
set aURL to (|NSURL|'s alloc()'s initWithString:aServer)
set aRequest to (NSURLRequest's alloc()'s initWithURL:aURL cachePolicy:(1) timeoutInterval:5.0)
if not ((NSURLConnection's sendSynchronousRequest:aRequest returningResponse:(missing value) |error|:(missing value)) is missing value) then set connectedServers to connectedServers & aServer
end repeat
return connectedServers
NOTE: As I see, makes sense convert this code to {on run, on idle} application (that is, background stay-open application) which would every 60 seconds check connections and write its states to text file. Then your main program can read the contents of this text file when is needed.
-- Here put the use statments and properties as is above
on run
-- Here create little RAM disk. Creating RAM disk:
set dName to "RAM Disk"
set dCapacity to 2048 --2MB
set aCmd to "diskutil erasevolume HFS+ '" & dName & "' `hdiutil attach -nomount ram://" & (dCapacity as string) & "`"
try
do shell script aCmd
end try
-- Here create new text file on RAM Disk
end run
on idle
set connectedServers to ""
repeat with aServer in theServers
set aURL to (|NSURL|'s alloc()'s initWithString:aServer)
set aRequest to (NSURLRequest's alloc()'s initWithURL:aURL cachePolicy:(1) timeoutInterval:5.0)
if (NSURLConnection's sendSynchronousRequest:aRequest returningResponse:(missing value) |error|:(missing value)) is missing value then
set end of connectedServers to "0"
else
set end of connectedServers to "1"
end if
end repeat
-- here put code which writes text connectedServers to text file
return 60 -- delay to check every 60 seconds
end idle
on quit
tell application "Finder" to eject "RAM DISK"
end quit
Save it as stay-open application. Then your main program can read this big string of “0” and “1” and get state of each server by offset in this string. To make things faster, and to not destroy hard disk, makes sense create little RAM disk.
As you see, the solution is not so simple. Good luck.