Ping site and return result in PHP

function urlExists($url=NULL) { if($url == NULL) return false; $ch = curl_init($url); curl_setopt($ch, CURLOPT_TIMEOUT, 5); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $data = curl_exec($ch); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if($httpcode>=200 && $httpcode<300){ return true; } else { return false; } } This was grabbed from this post on how to check if a URL exists. Because … Read more

Downloading large files reliably in PHP

Chunking files is the fastest / simplest method in PHP, if you can’t or don’t want to make use of something a bit more professional like cURL, mod-xsendfile on Apache or some dedicated script. $filename = $filePath.$filename; $chunksize = 5 * (1024 * 1024); //5 MB (= 5 242 880 bytes) per one chunk of … Read more

How to call a MySQL stored procedure from within PHP code?

I now found solution by using mysqli instead of mysql. <?php // enable error reporting mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); //connect to database $connection = mysqli_connect(“hostname”, “user”, “password”, “db”, “port”); //run the store proc $result = mysqli_query($connection, “CALL StoreProcName”); //loop the result set while ($row = mysqli_fetch_array($result)){ echo $row[0] . ” – ” . + $row[1]; } … Read more

Can you ‘exit’ a loop in PHP?

You are looking for the break statement. $arr = array(‘one’, ‘two’, ‘three’, ‘four’, ‘stop’, ‘five’); while (list(, $val) = each($arr)) { if ($val == ‘stop’) { break; /* You could also write ‘break 1;’ here. */ } echo “$val<br />\n”; }

Why is my $_ENV empty?

Turns out there was two issues here: 1. $_ENV is only populated if php.ini allows it, which it doesn’t seem to do by default, at least not in the default WAMP server installation. ; This directive determines which super global arrays are registered when PHP ; starts up. If the register_globals directive is enabled, it … Read more