homepage Welcome to WebmasterWorld Guest from 54.227.171.163
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Sending information to a server
ocon

5+ Year Member



 
Msg#: 4633851 posted 10:32 pm on Dec 27, 2013 (gmt 0)

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

 

JD_Toims

WebmasterWorld Senior Member Top Contributors Of The Month



 
Msg#: 4633851 posted 11:20 pm on Dec 27, 2013 (gmt 0)

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.]

ocon

5+ Year Member



 
Msg#: 4633851 posted 3:58 pm on Dec 28, 2013 (gmt 0)

Thank you. Unfortunately the only window I have is in this PHP script, although JavaScript would seem ideal.

JD_Toims

WebmasterWorld Senior Member Top Contributors Of The Month



 
Msg#: 4633851 posted 8:52 pm on Dec 28, 2013 (gmt 0)

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;
}
?>

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved