0

Hi I have this code sample:

<form action="" method="post">
    <input type="submit" name="submit" value="submit">
</form>

<?php 
$db = new mysqli("localhost", "root", "root", "testurl");
if (isset($_POST['submit'])) {
    $query = "SELECT * from url ORDER BY id";
    $result = $db->query($query);

    // fetch (for sample purpose only)
    $data = array();
    while ($row = $result->fetch_array()) {
        $data[] = $row;
    }
    foreach ($data as $row) {
        $url = $row['url_data'];
        // do ajax here to check each url
    }
}
?>

All the code is working well until I display the data inside foreach loop. My problem is the list in SQL is lot of data and when I use a foreach loop the server will timeout. set_time_limit is not an option and I need this to be done in AJAX to avoid timeout.

The point is to check each URL that I get from the query using AJAX.

Anyone can help me?

Thank you Patty

Staghouse
  • 167
  • 12
pattygeek
  • 103
  • 5
  • 1
    Yo obviously dont know what ajax is. Ajax is run from the browser and may well call out to PHP code on the server almost as if it were a subroutine. But you cannot run AJAX calls from PHP – RiggsFolly May 02 '18 at 21:30
  • 2
    Do you possibly mean CURL rather than AJAX – RiggsFolly May 02 '18 at 21:32
  • 1
    You can't do ajax-requests from PHP, but you can do async HTTP calls, if you use some library like Guzzle. – M. Eriksson May 02 '18 at 21:32
  • 1
    @RiggsFolly Hi riggs, thank you for the respon, and I know I still new in this "code thing" still learning :) yes it's possible to use curl but I just worried about the timeout because the data quite big. – pattygeek May 02 '18 at 21:36
  • 1
    @MagnusEriksson will try to look what Guzzle is, thank you :) – pattygeek May 02 '18 at 21:36
  • Actually just want to display each data on sql and run it each to check do the url still alive or not, and want to be done in AJAX to avoid timeout – pattygeek May 02 '18 at 21:40
  • You could run this as a PHP CLI or CRON job if that makes logical sense to what you are trying to achieve – RiggsFolly May 02 '18 at 21:43

0 Answers0