best function to use ~ file_get_contents or ?
best function to use ~ file_get_contents or ?
am 16.09.2009 00:36:32 von crm
Hi All,
Not sure of the best approach, need your feedback. I have 4 images on a
website. These are used in navigation. When I load a reference webpage on my
local machine the local page calls 4 images from an external website, each
image will be on a different domain.
What I want to see is if the navigation images/buttons can be loaded/displayed
in my browser. If they can, then I will display the images on my local page.
If the images cannot be loaded, then this indicates some connection issue and
the result will be some text like 'Site Offline'. So just by glancing at my
local machine reference page I can tell if one or more of the different sites
is or is not available.
So what is the best function to use?
if ( @file_get_contents( DOMAIN_PATH . "images/navigation/nav_globalissa.png" )):
or ???
Please also cc info@globalissa.com
Thanks for any helpful suggestions.
Sincerely,
Rob
Global I.S. S.A.
Software Powers the Net
Email: crm at globalissa dot com
* * * The Forge of Globalissa ~ PHP Foobar Machine * * *
http://globalissa.com/forge/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: best function to use ~ file_get_contents or ?
am 16.09.2009 03:50:44 von Tommy Pham
--- On Tue, 9/15/09, CRM wrote:
> From: CRM
> Subject: [PHP] best function to use ~ file_get_contents or ?
> To: php-general@lists.php.net
> Cc: info@globalissa.com
> Date: Tuesday, September 15, 2009, 5:36 PM
> Hi All,
> Not sure of the best approach, need your feedback. I have 4
> images on a
> website. These are used in navigation. When I load a
> reference webpage on my
> local machine the local page calls 4 images from an
> external website, each
> image will be on a different domain.
>
> What I want to see is if the navigation images/buttons can
> be loaded/displayed
> in my browser. If they can, then I will display the images
> on my local page.
> If the images cannot be loaded, then this indicates some
> connection issue and
> the result will be some text like 'Site Offline'. So just
> by glancing at my
> local machine reference page I can tell if one or more of
> the different sites
> is or is not available.
>
> So what is the best function to use?
>
> if ( @file_get_contents( DOMAIN_PATH .
> "images/navigation/nav_globalissa.png" )):
>
> or ???
>
> Please also cc info@globalissa.com
>
> Thanks for any helpful suggestions.
>
> Sincerely,
>
> Rob
> Global I.S. S.A.
> Software Powers the Net
> Email: crm at globalissa dot com
>
> * * * The Forge of Globalissa ~ PHP Foobar Machine * * *
> http://globalissa.com/forge/
>
>
Shouldn't it be:
if ( @file_get_contents( DOMAIN_PATH .
"images/navigation/nav_globalissa.png", FILE_BINARY))
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: best function to use ~ file_get_contents or ?
am 16.09.2009 08:38:26 von Gaurav Kumar
--001636ed68e6707e580473ac257b
Content-Type: text/plain; charset=ISO-8859-1
There is no best function as such. Everything depends upon your requirement.
You can also use fopen() to get the contents of the remote file and do some
error handling that if you get any content then display image else a message
etc..
Gaurav Kumar
(Team Lead- open source)
oswebstudio.com
On Wed, Sep 16, 2009 at 4:06 AM, CRM wrote:
> Hi All,
> Not sure of the best approach, need your feedback. I have 4 images on a
> website. These are used in navigation. When I load a reference webpage on
> my
> local machine the local page calls 4 images from an external website, each
> image will be on a different domain.
>
> What I want to see is if the navigation images/buttons can be
> loaded/displayed
> in my browser. If they can, then I will display the images on my local
> page.
> If the images cannot be loaded, then this indicates some connection issue
> and
> the result will be some text like 'Site Offline'. So just by glancing at my
> local machine reference page I can tell if one or more of the different
> sites
> is or is not available.
>
> So what is the best function to use?
>
> if ( @file_get_contents( DOMAIN_PATH .
> "images/navigation/nav_globalissa.png" )):
>
> or ???
>
> Please also cc info@globalissa.com
>
> Thanks for any helpful suggestions.
>
> Sincerely,
>
> Rob
> Global I.S. S.A.
> Software Powers the Net
> Email: crm at globalissa dot com
>
> * * * The Forge of Globalissa ~ PHP Foobar Machine * * *
> http://globalissa.com/forge/
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--001636ed68e6707e580473ac257b--
Re: best function to use ~ file_get_contents or ?
am 16.09.2009 10:26:29 von Ashley Sheridan
On Wed, 2009-09-16 at 12:08 +0530, Gaurav Kumar wrote:
> There is no best function as such. Everything depends upon your requirement.
>
> You can also use fopen() to get the contents of the remote file and do some
> error handling that if you get any content then display image else a message
> etc..
>
> Gaurav Kumar
> (Team Lead- open source)
> oswebstudio.com
>
>
>
> On Wed, Sep 16, 2009 at 4:06 AM, CRM wrote:
>
> > Hi All,
> > Not sure of the best approach, need your feedback. I have 4 images on a
> > website. These are used in navigation. When I load a reference webpage on
> > my
> > local machine the local page calls 4 images from an external website, each
> > image will be on a different domain.
> >
> > What I want to see is if the navigation images/buttons can be
> > loaded/displayed
> > in my browser. If they can, then I will display the images on my local
> > page.
> > If the images cannot be loaded, then this indicates some connection issue
> > and
> > the result will be some text like 'Site Offline'. So just by glancing at my
> > local machine reference page I can tell if one or more of the different
> > sites
> > is or is not available.
> >
> > So what is the best function to use?
> >
> > if ( @file_get_contents( DOMAIN_PATH .
> > "images/navigation/nav_globalissa.png" )):
> >
> > or ???
> >
> > Please also cc info@globalissa.com
> >
> > Thanks for any helpful suggestions.
> >
> > Sincerely,
> >
> > Rob
> > Global I.S. S.A.
> > Software Powers the Net
> > Email: crm at globalissa dot com
> >
> > * * * The Forge of Globalissa ~ PHP Foobar Machine * * *
> > http://globalissa.com/forge/
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
The way I've always seen this approached before is by using the wget
command, which can be asked to just return the headers for a page. In
your case you'd be looking for all 200 codes, which means that all the
sites are up. This is faster than asking to return a full image each
time.
Thanks,
Ash
http://www.ashleysheridan.co.uk
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
RE: best function to use ~ file_get_contents or ?
am 16.09.2009 11:17:10 von Andrea Giammarchi
--_3e3f17a9-d549-436a-b85f-42a34dabddb6_
Content-Type: text/plain; charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable
> The way I've always seen this approached before is by using the wget
> command=2C which can be asked to just return the headers for a page. In
> your case you'd be looking for all 200 codes=2C which means that all the
> sites are up. This is faster than asking to return a full image each
> time.
but slower 'cause for each image you need to requests
On the other hand=2C file_get_contents could return false positives cause t=
he fact we are asking for an image does not mean an image will be returned.
I would go for a curl call=2C where you can have both headers and content s=
o in one call you can handle every case. A bit slower than a HEAD request=
=2C surely faster than a HEAD request plus the REQUEST.
One more thing=2C I hope you have rights to grab these images=2C usually th=
ere are APIs or webservices when a website would like to share images in th=
is way but it does not seem the case here ...
Regards
____________________________________________________________ _____
Drag n=92 drop=97Get easy photo sharing with Windows Live=99 Photos.
http://www.microsoft.com/windows/windowslive/products/photos .aspx=
--_3e3f17a9-d549-436a-b85f-42a34dabddb6_--
RE: best function to use ~ file_get_contents or ?
am 16.09.2009 11:25:10 von Ashley Sheridan
--=-Fjn6V8uNw5ffXeYwb4Cv
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
On Wed, 2009-09-16 at 11:17 +0200, Andrea Giammarchi wrote:
>=20
>=20
> > The way I've always seen this approached before is by using the wget
> > command, which can be asked to just return the headers for a page. In
> > your case you'd be looking for all 200 codes, which means that all the
> > sites are up. This is faster than asking to return a full image each
> > time.
>=20
> but slower 'cause for each image you need to requests
>=20
> On the other hand, file_get_contents could return false positives cause t=
he fact we are asking for an image does not mean an image will be returned.
>=20
> I would go for a curl call, where you can have both headers and content s=
o in one call you can handle every case. A bit slower than a HEAD request, =
surely faster than a HEAD request plus the REQUEST.
>=20
> One more thing, I hope you have rights to grab these images, usually ther=
e are APIs or webservices when a website would like to share images in this=
way but it does not seem the case here ...
>=20
> Regards
>=20
> ____________________________________________________________ _____
> Drag nâ=99 dropâ=94Get easy photo sharing with Windows Live=E2=
¢ Photos.
>=20
> http://www.microsoft.com/windows/windowslive/products/photos .aspx
Requesting only the headers is a lot faster than requesting the headers
AND the file itself. I'd also not look to grab an image anyway, try
grabbing just the HTML of a web-page. You get the headers, and the HTML
is likely to be very small in size. Not only that, you can perform other
tests on the returned HTML, for example to see if PHP is still running
on the remote site. All of this is very easy to accomplish with a single
line call to wget.
Thanks,
Ash
http://www.ashleysheridan.co.uk
--=-Fjn6V8uNw5ffXeYwb4Cv--
RE: best function to use ~ file_get_contents or ?
am 16.09.2009 11:37:07 von Andrea Giammarchi
--_1c97ed68-488d-48ef-a03f-2177e66edd89_
Content-Type: text/plain; charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable
This is what I said=2C except if you want to grab the content you need to r=
equest HEAD first and eventually GET=2C and this is slower than just GET pa=
rsing headers.
In any case=2C curl is the answer=2C imho.
Regards
Requesting only the headers is a lot faster than requesting the headers AND=
the file itself.
____________________________________________________________ _____
Drag n=92 drop=97Get easy photo sharing with Windows Live=99 Photos.
http://www.microsoft.com/windows/windowslive/products/photos .aspx=
--_1c97ed68-488d-48ef-a03f-2177e66edd89_--