Welcome to WebmasterWorld Guest from 54.158.143.40

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Sending information to a server

   
10:32 pm on Dec 27, 2013 (gmt 0)

5+ Year Member Top Contributors Of The Month



During a plugin's installation there is an option to announce that the website is using the plugin.

If $anncounce=true; a call is made during installation to the plugin's server that includes the website's url. If possible I'd like to improve this code.

...
if($announce) file_get_contents('http://www.pluginserver.tld/announce/?url='.urlencode($url));
...

The installation just needs to "ping" the server, it doesn't recieve or use any information from it. Is file_get_contents the best method?

I also don't want to slow down the installation or cause any errors if the server is unresponsive. I just want the script to quickly attempt to report the installation and move on.

Should I use something less strict or stricter than "if($announce)"?

Thanks
11:20 pm on Dec 27, 2013 (gmt 0)

WebmasterWorld Senior Member Top Contributors Of The Month



if($announce) is fine, but personally, I would not likely use PHP to make the ping, unless there was no other way. What I'd be much more inclined to do instead is use JS and make the ping asynchronous -- I'd even set a "flag" to trigger the JS call/creation via the if($announce) conditional if necessary.

eg

[something like the following, depending on the exact script(s)/situation/application(s)]

if($announce) { $ping=true; }

then later:

if($ping) {
// echo some JS to make an asynchronous request here
}

[You could probably just move the if($announce) conditional to the correct place in the output and not use two conditionals, but the preceding is merely an example of the "idea" or "theory" I'd work with and not likely the "absolute best" implementation.]
3:58 pm on Dec 28, 2013 (gmt 0)

5+ Year Member Top Contributors Of The Month



Thank you. Unfortunately the only window I have is in this PHP script, although JavaScript would seem ideal.
8:52 pm on Dec 28, 2013 (gmt 0)

WebmasterWorld Senior Member Top Contributors Of The Month



In that case, I'd probably move it to the end of the script and send the info to the browser before making the "ping".

eg

// The PHP that "does stuff" for people to see ends here.

ob_flush();

if($announce) {
file_get_contents('http://www.pluginserver.tld/announce/?url='.urlencode($url));
exit;
}
?>