-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor read_and_post to use sendData() inside while loop
- Loading branch information
1 parent
ebe82af
commit f0de05e
Showing
1 changed file
with
28 additions
and
23 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,38 @@ | ||
<?php | ||
|
||
error_log('YANPIWS Start read_and_post'); | ||
require_once 'get_data.php'; | ||
getConfig(); | ||
|
||
error_log('config loaded'); | ||
if(defined('STDIN')){ | ||
while ($f = fgets(STDIN)) { | ||
$dataArray = json_decode($f, true); | ||
$dataArray = json_decode($f, true); | ||
sendData($YANPIWS, $dataArray); | ||
} | ||
} | ||
|
||
if(isset($YANPIWS['servers']) && is_array($YANPIWS['servers'])){ | ||
foreach ($YANPIWS['servers'] as $server){ | ||
if (isset($server['url']) && isset($server['password'])) { | ||
$url = $server['url'] . '/parse_and_save.php'; | ||
$dataArray['password'] = $server['password']; | ||
|
||
$ch = curl_init(); | ||
curl_setopt($ch, CURLOPT_URL,$url); | ||
curl_setopt($ch, CURLOPT_POST, 1); | ||
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($dataArray)); | ||
curl_setopt($ch, CURLOPT_HEADER, true); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||
|
||
// for debug or logging | ||
$server_output = curl_exec($ch); | ||
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); | ||
function sendData($YANPIWS, $dataArray){ | ||
if(isset($YANPIWS['servers']) && is_array($YANPIWS['servers'])){ | ||
foreach ($YANPIWS['servers'] as $server){ | ||
if (isset($server['url']) && isset($server['password'])) { | ||
$url = $server['url'] . '/parse_and_save.php'; | ||
$dataArray['password'] = $server['password']; | ||
|
||
$ch = curl_init(); | ||
curl_setopt($ch, CURLOPT_URL,$url); | ||
curl_setopt($ch, CURLOPT_POST, 1); | ||
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($dataArray)); | ||
curl_setopt($ch, CURLOPT_HEADER, true); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||
|
||
// for debug or logging | ||
$server_output = curl_exec($ch); | ||
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); | ||
$bytes = curl_getinfo($ch, CURLINFO_REQUEST_SIZE); | ||
|
||
curl_close ($ch); | ||
error_log("made curl call to $url, got response code $httpcode "); | ||
} | ||
} | ||
} | ||
curl_close ($ch); | ||
error_log("YANPIWS made curl call to $url, sent $bytes bytes, got response code $httpcode "); | ||
} | ||
} | ||
} | ||
} |