pawelnowacki

Soap http://softcom.wroc.pl

Jun 13th, 2016
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.40 KB | None | 0 0
  1. <?php
  2. //Environment:
  3. //  - Server: PHP 7.0.4-7ubuntu2.1 Development Server started at Mon Jun 13 18:15:44 2016
  4. //  - PHP: PHP 7.0.4-7ubuntu2.1 (cli) ( NTS )
  5. //  - MySQL: Server version: 5.5.48-cll MySQL Community Server (GPL)
  6.  
  7. /**
  8. -- noinspection SqlDialectInspectionForFile
  9. -- noinspection SqlNoDataSourceInspectionForFile
  10.  
  11. CREATE TABLE `t03_mySrvClients` (
  12.     `clientId` mediumint(8) unsigned NOT NULL,
  13.     `clientLastSeenIp` int(10) unsigned NOT NULL,
  14.     `clientCreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  15.     `clientLastSeenTime` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  16.     UNIQUE KEY `unique_clientId` (`clientId`)
  17. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  18.  
  19.  
  20. CREATE TABLE `t03_mySrvClientsHistory` (
  21.     `clientId` mediumint(8) unsigned NOT NULL,
  22.     `clientOSVersion` varchar(64) NOT NULL,
  23.     `clientIp` int(10) unsigned NOT NULL,
  24.     `clientSoftwareVersion` varchar(64) NOT NULL,
  25.     `clientFreeSpace` varchar(64) NOT NULL,
  26.     `clientErrors` enum('Y','N') NOT NULL DEFAULT 'N',
  27.     `clientReportTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  28.     KEY `index_clientId` (`clientId`),
  29.     KEY `index_clientId_clientReportTime` (`clientId`,`clientReportTime`),
  30.     CONSTRAINT
  31.     `lnk_t03_mySrvClientsHistory_t03_mySrvClients`
  32.     FOREIGN KEY (`clientId`)
  33.     REFERENCES `t03_mySrvClients` (`clientId`)
  34.     ON DELETE CASCADE ON UPDATE CASCADE
  35. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  36. **/
  37. //Filename: SoapClient.php
  38. //Author: PN
  39.  
  40. $myCli = new SoapClient(null,
  41.     [
  42.         'location' => 'http://localhost:8000/SoapServer.php',
  43.         'uri' => 'http://localhost:8000/SoapClient.php'
  44.     ]);
  45.  
  46. for($i1 = 0; $i1 < 20; $i1++) {
  47.     for ($i2 = 1; $i2 < 50; $i2++) {
  48.         $myCli->report(
  49.             [
  50.                 'clientId' => $i2,
  51.                 'clientOsVersion' => 'MyOs',
  52.                 //'clientIp' => rand(0,1)==1?'8.8.8.8':'8.8.4.4'
  53.                 'clientErrors' => (bool)rand(0, 1),
  54.                 'clientOSVersion' => 'MyOs-' . time(),
  55.                 'clientSoftwareVersion' => 'MySoftware-' . time(),
  56.                 'clientFreeSpace' => rand(1024 * 1024, 100 * 10024 * 1024),
  57.             ]
  58.         );
  59.     }
  60. }
  61.  
  62.  
  63.  
  64.  
  65.  
  66. <?php
  67. //Filename: SoapServer.php
  68. //Author: PN
  69.  
  70. define('STATUS_ERR',-1);
  71. define('STATUS_OK',0);
  72.  
  73. class MySrv
  74. {
  75.     private function getRealIp()
  76.     {
  77.         if (isset($_SERVER['HTTP_CLIENT_IP']) && !empty($_SERVER['HTTP_CLIENT_IP']))
  78.         {
  79.             return $_SERVER['HTTP_CLIENT_IP'];
  80.         }
  81.         elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && !empty($_SERVER['HTTP_X_FORWARDED_FOR']))
  82.         {
  83.             return $_SERVER['HTTP_X_FORWARDED_FOR'];
  84.         }
  85.         else
  86.         {
  87.             return isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '0.0.0.0';
  88.         }
  89.     }
  90.  
  91.     public function report(array $params)
  92.     {
  93.         try
  94.         {
  95.             $reportTime = date('Y-m-d H:i:s');
  96.             $db = new PDO('mysql:host=teleit.pl;dbname=teleitpl_pp;charset=utf8', 'teleitpl_pp', 'HASLO');
  97.             $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  98.             $stmt = $db->prepare('
  99.                INSERT INTO
  100.                    t03_mySrvClients
  101.                    ( clientId, clientLastSeenIp, clientLastSeenTime, clientCreatedTime)
  102.                VALUES
  103.                    (:clientId,:clientLastSeenIp,:clientLastSeenTime,:clientCreatedTime)
  104.                ON DUPLICATE KEY UPDATE
  105.                    clientLastSeenIp = :clientLastSeenIp,
  106.                    clientLastSeenTime = :clientLastSeenTime'
  107.             );
  108.             $stmt->bindValue(':clientId', $params['clientId'], PDO::PARAM_INT);
  109.             $stmt->bindValue(':clientLastSeenIp', ip2long(self::getRealIp()), PDO::PARAM_INT);
  110.             $stmt->bindValue(':clientCreatedTime', $reportTime, PDO::PARAM_STR);
  111.             $stmt->bindValue(':clientLastSeenTime', $reportTime, PDO::PARAM_STR);
  112.             $stmt->execute();
  113.  
  114.             $stmt = $db->prepare('
  115.                INSERT INTO
  116.                    t03_mySrvClientsHistory
  117.                    ( clientId, clientIp, clientOSVersion, clientReportTime,
  118.                      clientSoftwareVersion, clientFreeSpace, clientErrors)
  119.                VALUES
  120.                    (:clientId,:clientIp,:clientOSVersion,:clientReportTime,
  121.                     :clientSoftwareVersion,:clientFreeSpace,:clientErrors)'
  122.             );
  123.             $stmt->bindValue(':clientId', $params['clientId'], PDO::PARAM_INT);
  124.             $stmt->bindValue(':clientIp', ip2long(self::getRealIp()), PDO::PARAM_INT);
  125.             $stmt->bindValue(':clientOSVersion', $params['clientOSVersion'], PDO::PARAM_STR);
  126.             $stmt->bindValue(':clientReportTime', $reportTime, PDO::PARAM_STR);
  127.             $stmt->bindValue(':clientSoftwareVersion', $params['clientSoftwareVersion'], PDO::PARAM_STR);
  128.             $stmt->bindValue(':clientFreeSpace', $params['clientFreeSpace'], PDO::PARAM_STR);
  129.             $stmt->bindValue(':clientErrors', $params['clientErrors']?'Y':'N', PDO::PARAM_STR);
  130.             $stmt->execute();
  131.  
  132.             return json_encode(['status' => STATUS_OK, 'info' => null]);
  133.         }
  134.         catch(Exception $e)
  135.         {
  136.             return json_encode(['status' => STATUS_ERR, 'info' => $e->getMessage()]);
  137.         }
  138.     }
  139. }
  140. $mySrv = new SoapServer(null, ['uri' => 'http://localhost:8000/SoapServer.php']);
  141. $mySrv->setClass('MySrv');
  142. $mySrv->handle();
Add Comment
Please, Sign In to add comment