Asked  2 Years ago    Answers:  5   Viewed   57 times

How can I check if I'm connected to the internet from my PHP script which is running on my dev machine?

I run the script to download a set of files (which may or may not exist) using wget. If I try the download without being connected, wget proceeds to the next one thinking the file is not present.

 Answers

1
<?php
function is_connected()
{
    $connected = @fsockopen("www.example.com", 80); 
                                        //website, port  (try 80 or 443)
    if ($connected){
        $is_conn = true; //action when connected
        fclose($connected);
    }else{
        $is_conn = false; //action in connection failure
    }
    return $is_conn;

}
?>
Monday, September 26, 2022
5

If none of the above works for you, and you would still like to run under SSL, you could always write the file to disk and provide a download link, or you could prompt the user for an email address and email the file as an attachment. If you go the email route, PHPMailer has a fairly easy way of sending attachments. I'm not 100% for sure, but I think the file needs to be written to disk before it can be attached using PHPMailer, but you can always unlink the file immediately after send.

Thursday, December 1, 2022
 
ctd
 
ctd
2

I would do this inside the loop where you fetch rows from DB2.

Assume you have a PDO connection $pdo to your MySQL database.

$stmt = $pdo->prepare("
    INSERT INTO skuplacement (sku_id, groupID, dealerID, startDate, expirationDate, placements)
    SELECT id, groupID, :DEALER, :SHIPDATE, :PLACEMENTS
    FROM sku
    WHERE groupID=:STYLE AND frame=:FRAME AND cover=:COVER AND color=:COLOR
");

$pdo->beginTransaction();
$i = 0;
while($db2row = odbc_fetch_array($result)) {

    if(++$i % 1000 == 0) {
        $pdo->commit();
        $pdo->beginTransaction();
    }

    $stmt->execute($db2row);

}
$pdo->commit();

PDO allows you to pass an associative array to execute(), and the array keys are matched to the named parameter placeholders in the prepared query. But your associative array must have exactly the same set of keys as the parameters.

So you will need to change your DB2 query to return only STYLE, DEALER, FRAME, COVER, COLOR, SHIPDATE, PLACEMENTS.

Tuesday, November 22, 2022
 
1

A few things that need to be fixed. first you are using mysql when you should be using mysqli or PDO. Second you are using post data without any escaping at all. Thirdly, you don't need this select and update. You can do it in a single statement.

$query = "UPDATE tinyblog SET views = views + 1 WHERE id = (SELECT id FROM tinyblog where id=:article)"
$db = new PDO('mysql:host=localhost;dbname=mydb', 'username', 'password');
$stmt = $db->prepare($query);
$stmt->execute(array(":article"=>$article_id));

What we are doing here is creating a prepared statement with one place holder. We have named it as :article but it could have been left as ? instead.

Then when the query is executed you need to fill in the missing bits by passing in parameters. That's what we are doing in the last step with array(":article"=>$article_id)

Since it's a named parameter, we use an associative array. Alternatively you could have called execute without any parameters if you had called bindParam first.

Monday, November 14, 2022
 
fumu_7
 
16

Generally, most ISPs give you far more download bandwidth than upload bandwidth. It's possible that your upload stream is becoming saturated with torrent traffic, and since it is so much smaller than your download pipe, this is keeping your other clients from making requests. You need to have enough upload bandwidth to initiate requests to web sites and other services. While you use your download bandwidth to actually download the web page data, the upload bandwidth is needed for that initial request to the site to ask for the data.

Try limiting your upload bandwidth in torrent so that it doesn't use too much.

Same thing with your IMCP (ping), it's all on the upload side (which is super tiny compared to download.)

Also, a high amount of uncorrectable code words is a sign of signal issues.

Sunday, September 25, 2022
 
dbotha
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 

Browse Other Code Languages