Ignore errors if no internet connection

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
serendipity
Posts: 3360
Joined: 07 May 2007 18:14
Location: NJ/NY

Ignore errors if no internet connection

Post by serendipity »

I am trying a script which will check for XY updates on startup. It works nicely but have not posted it yet, because if I donot have internet connection then it throws an error on XY startup which is kind of ugly.
Is there a way to check that I have internet connection so that I an include that in my script? Or altenatively, if command readurl is throwing an error then someway of ignoring this?
Thanks.
PS: maybe I'll just post this script anyway.

admin
Site Admin
Posts: 66350
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Ignore errors if no internet connection

Post by admin »

I added something experimentally. Next version add a 4th parameter and set it to 1:

Code: Select all

$ReadURL = readurl("http://www.xyplorer.com/xyfc/viewtopic.php?t=4&start=0&sd=d", , , 1); 
Now readurl() should return silently when you are offline and $ReadURL will be "" (empty).

serendipity
Posts: 3360
Joined: 07 May 2007 18:14
Location: NJ/NY

Re: Ignore errors if no internet connection

Post by serendipity »

admin wrote:I added something experimentally. Next version add a 4th parameter and set it to 1:

Code: Select all

$ReadURL = readurl("http://www.xyplorer.com/xyfc/viewtopic.php?t=4&start=0&sd=d", , , 1); 
Now readurl() should return silently when you are offline and $ReadURL will be "" (empty).
Thanks, I'll try that in the next version.

serendipity
Posts: 3360
Joined: 07 May 2007 18:14
Location: NJ/NY

Re: Ignore errors if no internet connection

Post by serendipity »

Thanks! it works now. I'll update the script.

admin
Site Admin
Posts: 66350
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Ignore errors if no internet connection

Post by admin »

serendipity wrote:Thanks! it works now. I'll update the script.
Actually I wonder if this should be the hard-coded default functionality anyway! What do you think?

PeterH
Posts: 2827
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Ignore errors if no internet connection

Post by PeterH »

admin wrote:
serendipity wrote:Thanks! it works now. I'll update the script.
Actually I wonder if this should be the hard-coded default functionality anyway! What do you think?
I still didn't understand, what happens till now...

But if I understand it right, it doesn't seem bad, if readurl() returns "" when no connection is possible, instead of showing an error.
(Though I didn't use it :roll: )

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Ignore errors if no internet connection

Post by TheQwerty »

Technically, it should be possible for the script to distinguish between not being connected and an empty return from the URL. It would really be best if we could somehow get the resulting HTTP status as well.


That said, I don't actually need such functionality so I'm not opposed to just making it return "". :P

admin
Site Admin
Posts: 66350
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Ignore errors if no internet connection

Post by admin »

TheQwerty wrote:Technically, it should be possible for the script to distinguish between not being connected and an empty return from the URL. It would really be best if we could somehow get the resulting HTTP status as well.
Yes, agreed. I will leave at the current state for the time being. Some fine day I will add optional output arguments...

Post Reply