Created
March 15, 2022 09:17
-
-
Save andyg2/1aa56a096ed6166b239af46ce33cd47c to your computer and use it in GitHub Desktop.
Write Stream to File
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 | |
$ip = '192.168.2.113'; | |
// 192.168.2.114 | |
// 192.168.2.120 | |
$path = './'.$ip.'-stream-'.date('Y-m-d-H-i-s').'.xml'; | |
$url = 'http://'.$ip.'/clickit/analyticsdata.cgi?timeout=100000'; | |
do_capture($url, $path); | |
function do_capture($url, $path){ | |
touch($path); | |
if ($stream = fopen($url, 'r')) { | |
// Open save file at end of file | |
if($fh = fopen($path, 'a')){ | |
$contents = stream_get_contents($stream); | |
if($contents){ | |
if(fwrite($fh, $contents)){ | |
// OK | |
}else{ | |
// cannot write contents | |
touch($path); | |
if(!file_exists($path)){ | |
exit(10); // not creatable- HD full? | |
}else{ | |
if(!is_writable($path)){ | |
exit(9); // not writable - HD full? | |
} | |
} | |
} | |
}else{ | |
// OK, no contents | |
} | |
}else{ | |
// cannot open save file for writing | |
sleep(10); | |
exit; | |
} | |
}else{ | |
// cannot open stream for reading | |
sleep(10); | |
exit; | |
} | |
// return(do_capture($url, $path)); | |
} | |
// no matter what, just reload. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment