0

This is the process that needs to wait. It is basically a snippet to check a website's status. The problem is if I put this in a php file without any loader, it will take some time to load the whole page.

So I think I need to use a loader to run this process in background.

Do you have any idea on how to put this function in a jQuery loader so that it runs in background, while the rest of the page loads?

<?php
function Visit($url){
       $agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";$ch=curl_init();
       curl_setopt ($ch, CURLOPT_URL,$url );
       curl_setopt($ch, CURLOPT_USERAGENT, $agent);
       curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
       curl_setopt ($ch,CURLOPT_VERBOSE,false);
       curl_setopt($ch, CURLOPT_TIMEOUT, 5);
       curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, FALSE);
       curl_setopt($ch,CURLOPT_SSLVERSION,3);
       curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, FALSE);
       $page=curl_exec($ch);
       //echo curl_error($ch);
       $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
       curl_close($ch);
       if($httpcode>=200 && $httpcode<300) return true;
       else return false;
}
$load = "http://www.somesite.com";
if (Visit($load))
       echo "Site is UP";
else
       echo "Site is DOWN";
?>

1 Answer 1

1

You need to put this function in page

And then you need to specify what is the result div

Then you make the AJAX request

Let's make it in action

1 - assume the page is myfunciton.php Not that you need to call the function

2 - <div class="loaderResult">Loading...</div>

3 - The AJAX code, I am going to use jQuery

var url = "http://www.example.com/"; 
$(document).ready(function(){ 
   $.ajax({
      url: "myfunction.php?url="+url,
      type: "post",
      success: function(result){
          alert("success");
           $(".loaderResult").html(result);
      },
      error:function(){
          alert("failure");
      }   
    });
});

You can pass the value of the URL in other ways

Note that the URL value now in $_GET['url'];

I hope this can help :)

Sign up to request clarification or add additional context in comments.

1 Comment

Hey sorry for the VERY late reply. I've been trying to put the script into a file (check.php) and I put the JS script into another file (script.js). Now all I have to do is call it by a class name in HTML. I still couldn't understand how to work with AJAX. Can you guide me through this? Thanks anyway for the info.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.