Created
May 10, 2017 21:03
-
-
Save Thijzer/41c6d417a9bf32f89183c45e0e141f7b to your computer and use it in GitHub Desktop.
SpeedTest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# /usr/local/bin/speedtest-cli | |
exec('/usr/bin/speedtest-cli --simple', $output); | |
$replacers = ["Ping:", "ms", "Download:", "Upload:", "Mbit/s"]; | |
// convert to useful array | |
$json['value1'] = trim(str_replace($replacers, '', $output[0])); | |
$json['value2'] = trim(str_replace($replacers, '', $output[1])); | |
$json['value3'] = trim(str_replace($replacers, '', $output[2])); | |
$key = ''; | |
$event = ''; | |
$url = 'https://maker.ifttt.com/trigger/'.$event.'/with/key/'.$key; | |
//Initiate cURL. | |
$ch = curl_init($url); | |
//Tell cURL that we want to send a POST request. | |
curl_setopt($ch, CURLOPT_POST, 1); | |
//Attach our encoded JSON string to the POST fields. | |
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($json)); | |
//Set the content type to application/json | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); | |
//Execute the request | |
$result = curl_exec($ch); | |
echo( $result ) . PHP_EOL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment