Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Environment:
- // - Server: PHP 7.0.4-7ubuntu2.1 Development Server started at Mon Jun 13 18:15:44 2016
- // - PHP: PHP 7.0.4-7ubuntu2.1 (cli) ( NTS )
- // - MySQL: Server version: 5.5.48-cll MySQL Community Server (GPL)
- /**
- -- noinspection SqlDialectInspectionForFile
- -- noinspection SqlNoDataSourceInspectionForFile
- CREATE TABLE `t03_mySrvClients` (
- `clientId` mediumint(8) unsigned NOT NULL,
- `clientLastSeenIp` int(10) unsigned NOT NULL,
- `clientCreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
- `clientLastSeenTime` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
- UNIQUE KEY `unique_clientId` (`clientId`)
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
- CREATE TABLE `t03_mySrvClientsHistory` (
- `clientId` mediumint(8) unsigned NOT NULL,
- `clientOSVersion` varchar(64) NOT NULL,
- `clientIp` int(10) unsigned NOT NULL,
- `clientSoftwareVersion` varchar(64) NOT NULL,
- `clientFreeSpace` varchar(64) NOT NULL,
- `clientErrors` enum('Y','N') NOT NULL DEFAULT 'N',
- `clientReportTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
- KEY `index_clientId` (`clientId`),
- KEY `index_clientId_clientReportTime` (`clientId`,`clientReportTime`),
- CONSTRAINT
- `lnk_t03_mySrvClientsHistory_t03_mySrvClients`
- FOREIGN KEY (`clientId`)
- REFERENCES `t03_mySrvClients` (`clientId`)
- ON DELETE CASCADE ON UPDATE CASCADE
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
- **/
- //Filename: SoapClient.php
- //Author: PN
- $myCli = new SoapClient(null,
- [
- 'location' => 'http://localhost:8000/SoapServer.php',
- 'uri' => 'http://localhost:8000/SoapClient.php'
- ]);
- for($i1 = 0; $i1 < 20; $i1++) {
- for ($i2 = 1; $i2 < 50; $i2++) {
- $myCli->report(
- [
- 'clientId' => $i2,
- 'clientOsVersion' => 'MyOs',
- //'clientIp' => rand(0,1)==1?'8.8.8.8':'8.8.4.4'
- 'clientErrors' => (bool)rand(0, 1),
- 'clientOSVersion' => 'MyOs-' . time(),
- 'clientSoftwareVersion' => 'MySoftware-' . time(),
- 'clientFreeSpace' => rand(1024 * 1024, 100 * 10024 * 1024),
- ]
- );
- }
- }
- <?php
- //Filename: SoapServer.php
- //Author: PN
- define('STATUS_ERR',-1);
- define('STATUS_OK',0);
- class MySrv
- {
- private function getRealIp()
- {
- if (isset($_SERVER['HTTP_CLIENT_IP']) && !empty($_SERVER['HTTP_CLIENT_IP']))
- {
- return $_SERVER['HTTP_CLIENT_IP'];
- }
- elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && !empty($_SERVER['HTTP_X_FORWARDED_FOR']))
- {
- return $_SERVER['HTTP_X_FORWARDED_FOR'];
- }
- else
- {
- return isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '0.0.0.0';
- }
- }
- public function report(array $params)
- {
- try
- {
- $reportTime = date('Y-m-d H:i:s');
- $db = new PDO('mysql:host=teleit.pl;dbname=teleitpl_pp;charset=utf8', 'teleitpl_pp', 'HASLO');
- $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $stmt = $db->prepare('
- INSERT INTO
- t03_mySrvClients
- ( clientId, clientLastSeenIp, clientLastSeenTime, clientCreatedTime)
- VALUES
- (:clientId,:clientLastSeenIp,:clientLastSeenTime,:clientCreatedTime)
- ON DUPLICATE KEY UPDATE
- clientLastSeenIp = :clientLastSeenIp,
- clientLastSeenTime = :clientLastSeenTime'
- );
- $stmt->bindValue(':clientId', $params['clientId'], PDO::PARAM_INT);
- $stmt->bindValue(':clientLastSeenIp', ip2long(self::getRealIp()), PDO::PARAM_INT);
- $stmt->bindValue(':clientCreatedTime', $reportTime, PDO::PARAM_STR);
- $stmt->bindValue(':clientLastSeenTime', $reportTime, PDO::PARAM_STR);
- $stmt->execute();
- $stmt = $db->prepare('
- INSERT INTO
- t03_mySrvClientsHistory
- ( clientId, clientIp, clientOSVersion, clientReportTime,
- clientSoftwareVersion, clientFreeSpace, clientErrors)
- VALUES
- (:clientId,:clientIp,:clientOSVersion,:clientReportTime,
- :clientSoftwareVersion,:clientFreeSpace,:clientErrors)'
- );
- $stmt->bindValue(':clientId', $params['clientId'], PDO::PARAM_INT);
- $stmt->bindValue(':clientIp', ip2long(self::getRealIp()), PDO::PARAM_INT);
- $stmt->bindValue(':clientOSVersion', $params['clientOSVersion'], PDO::PARAM_STR);
- $stmt->bindValue(':clientReportTime', $reportTime, PDO::PARAM_STR);
- $stmt->bindValue(':clientSoftwareVersion', $params['clientSoftwareVersion'], PDO::PARAM_STR);
- $stmt->bindValue(':clientFreeSpace', $params['clientFreeSpace'], PDO::PARAM_STR);
- $stmt->bindValue(':clientErrors', $params['clientErrors']?'Y':'N', PDO::PARAM_STR);
- $stmt->execute();
- return json_encode(['status' => STATUS_OK, 'info' => null]);
- }
- catch(Exception $e)
- {
- return json_encode(['status' => STATUS_ERR, 'info' => $e->getMessage()]);
- }
- }
- }
- $mySrv = new SoapServer(null, ['uri' => 'http://localhost:8000/SoapServer.php']);
- $mySrv->setClass('MySrv');
- $mySrv->handle();
Add Comment
Please, Sign In to add comment