I have a test script that connects to a webpage via ajax and returns a response. All is working accept if the network is down. The timeout takes to long to return a response. I would like to manually dial the timeout to 10 seconds instead of the default. Below is my test.html page. Attach is my php script that gets called by ajax. I have tried adding option to the file_get_contents but is doesn't seem to work.
<html>
<head>
function getXmlHttpRequestObject() {
if (window.XMLHttpRequest) {
return new XMLHttpRequest();
} else if(window.ActiveXObject) {
return new ActiveXObject("Microsoft.XMLHTTP");
} else {
alert("Please upgrade your browser to gain full functionality.");
}
}
//Our XmlHttpRequest object
var AJAXObject = getXmlHttpRequestObject();
function ajaxcall(url,functionname){
if (AJAXObject.readyState == 4 || AJAXObject.readyState == 0) {
AJAXObject.open("GET", url, true);
AJAXObject.onreadystatechange = functionname;
AJAXObject.send(null);
}
}
function testScript(){
var url = "test.php";
ajaxcall(url,checkTestScript);
}
function checkTestScript(){
if(AJAXObject.readyState == 4){
alert(AJAXObject.responseText);
}
}
</script>
</head>
<body>
<input type='button' onClick="testScript();" value="Click Here for Test"> Please Click The Button
</body>
</html>
What is the best way to send a GET request via https to a specific port and echo the response? Also a timeout of no more than 10 seconds must be in included.
Yes, that line has no effect on non-HTTPS sites. Thanks for sharing! ~Ray
PHP
PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.