Find Jobs
Hire Freelancers

PHP TCP SERVER LISTNER FOR XML MESSAGE AND PARSING -- 2

€30-250 EUR

クローズ
投稿日: 18日前

€30-250 EUR

完了時にお支払い
The code stuck when xml is wrong or long or when the close tagID is not found. I want to correct it in order to manage more connection. Consider that the XML is a camera that send more or less 1 xml every 2sec. Here my code: $listen_port = $this->cameraPort; $sock = socket_create_listen($listen_port); if ($sock === false) { $errorcode = socket_last_error(); $errormsg = socket_strerror($errorcode); $this->logger->error($this->logPrefix . "Couldn't create socket: [$errorcode] $errormsg"); return Command::FAILURE; } socket_getsockname($sock, $addr, $port); $this->logger->warning($this->logPrefix . "Server Listening on $addr:$port"); while ($c = socket_accept($sock)) { $this->logger->warning($this->logPrefix . "Socket Open"); $buffer = ""; $buffer2 = ""; while (true) { $line = socket_read($c, 512); $this->logger->warning( $this->logPrefix . "-------------------------------------------------------------------"); $this->logger->warning( $this->logPrefix . " $line " . $line ); if ($line === false || $line === '' || socket_last_error($sock) !== 0) { if ($line === false) $this->logger->warning($this->logPrefix . "LINE FALSE"); if ($line === '') $this->logger->warning($this->logPrefix . "LINE EMPTY </root> non ricevuto.... messaggio TCP interrotto "); if (socket_last_error($sock) !== 0) $this->logger->warning($this->logPrefix . "SOCKET LAST ERROR"); break; } elseif (socket_last_error($sock) !== 0) { $connectionReset = true; $this->logger->warning($this->logPrefix . "CONNECTION RESET"); break; } else { $line = trim($line); } $pos = strpos($line, "</root>"); if ($pos !== false) { $this->logger->warning($this->logPrefix . "POS FINISH"); $startRoot = strpos($buffer, "<?xml version"); if ($startRoot === false) { $startRoot = 0; } $buffer .= substr($line, $startRoot, $pos + strlen("</root>")); $buffer2 .= substr($line, $pos + strlen("</root>")); //$this->logger->alert("MESSAGGIO: " . $buffer); $xmlStartPos = strpos($buffer, "<?xml"); $buffer = trim(substr($buffer, $xmlStartPos), " \t\n\r\0\x0B\x0A"); $buffer = str_replace(">\n", ">", $buffer); $transitName = uniqid("transit-") . ".xml"; try { $this->logger->warning($this->logPrefix . "TRY PARSING"); $transit = $this->processTransit(trim($buffer)); // if this is a tutor clearance.. // find a transit from the other camera in the last 5 mins and with the same plate // if it exists, take the group_id // if it doesn't, generate a group id if ($secondCameraID !== null) { $transits = $transitRepo->getPlateTransit( $transit->getPlate(), $secondCameraID, $transit->getTransitTime()->format("Y-m-d H:i:s"), self::$tutor_transit_interval_minutes ); if (count($transits) == 1) { //if more, there's a problem $groupID = $transits[0]['tutor_group']; $transit->setTutorGroup($groupID); $transit->setTutorSequence(Constants::TRANSIT_SEQUENCE_EXIT); } else if (count($transits) == 0) { //generate group ID $transit->setTutorGroup(uniqid("g-")); $transit->setTutorSequence(Constants::TRANSIT_SEQUENCE_ENTRANCE); } else { //this shouldn't occur as we don't expect more than 1 transit in a tutor camera in 5 mins $this->logger->warning( $this->logPrefix . sprintf( "WARNING - found more than 1 transit in the last 5 mins for clearance %s and camera %d", $clearance->getId(), $secondCameraID ) ); $transit->setTutorSequence(Constants::TRANSIT_SEQUENCE_ERROR); } } else { $transit->setTutorGroup(uniqid("s-")); $transit->setTutorSequence(Constants::TRANSIT_SEQUENCE_ENTRANCE); } $this->logger->alert($this->logPrefix . "Transit acquired:"); $this->logger->alert($this->logPrefix . "Time: " . $transit->getTransitTime()->format("Y-m-d H:i:s")); $this->logger->alert($this->logPrefix . "Direction: " . $transit->getDirection()); $this->logger->alert($this->logPrefix . "Plate: " . $transit->getPlate()); $this->logger->alert($this->logPrefix . "Vehicle class: " . Utils::getVehicleClassString($transit->getVehicleClass())); $this->logger->alert($this->logPrefix . "Speed: " . $transit->getSpeed()); $this->logger->alert($this->logPrefix . "Radar distance: " . $transit->getRadarDistance()); $this->logger->alert($this->logPrefix . "Tutor group: " . $transit->getTutorGroup()); $this->logger->alert(""); switch ($transit->getTutorGroup()) { case Constants::TRANSIT_SEQUENCE_EXIT: $this->logger->warning($this->logPrefix . "Tutor sequence: EXIT"); break; case Constants::TRANSIT_SEQUENCE_ENTRANCE: $this->logger->warning($this->logPrefix . "Tutor sequence: ENTRANCE"); break; default: $this->logger->warning($this->logPrefix . "Tutor sequence: ERROR"); break; } $this->logger->alert(""); $this->logger->warning($this->logPrefix . "Entity created: " . $transit->getUid()); $em->persist($transit); $em->flush(); $this->logger->alert($this->logPrefix . "Transit created"); } catch (EmptyXMLException $e) { file_put_contents("/tmp/error-empty-" . $transitName, $e->getMessage()); $this->logger->error($this->logPrefix . "Error: Empty XML - /tmp/error-empty-" . $transitName); } catch (MissingImageInXMLException $e) { file_put_contents("/tmp/error-missing-image-" . $transitName, $e->getMessage()); $this->logger->error($this->logPrefix . "Error: Missing context image in XML - /tmp/error-missing-image-" . $transitName); } catch (\Exception $e) { file_put_contents("/tmp/error-" . $transitName, $e->getMessage()); $this->logger->error($this->logPrefix . "Error while parsing XML - /tmp/error-" . $transitName); $this->logger->error($this->logPrefix . $e->getTraceAsString()); } //check if there's another transit incoming if (empty($buffer2)) { break; } else { $buffer = $buffer2; $buffer2 = ""; } } else { $buffer .= $line; } } $this->logger->warning($this->logPrefix . "Closing socket"); socket_close($c); $buffer = ""; $buffer2 = ""; } socket_shutdown($sock, 2); socket_close($sock); return Command::SUCCESS;
プロジェクト ID: 38067333

プロジェクトについて

7個の提案
リモートプロジェクト
アクティブ 11日前

お金を稼ぎたいですか?

Freelancerで入札する利点

予算と期間を設定してください
仕事で報酬を得る
提案をご説明ください
登録して仕事に入札するのは無料です
この仕事に7人のフリーランサーが、平均€128 EURで入札しています
ユーザーアバター
Hi there I propose to modify the code by implementing a more robust XML parsing mechanism. Specifically, I plan to enhance error handling for cases where the XML structure is incorrect or incomplete. This will involve incorporating proper validation checks for opening and closing tags, as well as handling long or malformed XML data gracefully. By making these improvements, we can ensure that the code can effectively manage a higher volume of connections without getting stuck due to XML parsing issues. This will enhance the overall reliability and performance of the system when receiving XML data from cameras at a rate of approximately one XML every 2 seconds. I can provide links to similar works from my portfolio. Please go through my profile its 15 years old see the work I did over the years. ---> No Win No Fee means that your satisfaction is my utmost priority. <---- Lets discuss the job details. Moreover, I am willing to start the job and perform tasks without even being hired; it is just to show my commitment to this project. Looking forward to hear from you. Regards Shah
€163 EUR 7日以内
4.9 (5 レビュー)
3.9
3.9
ユーザーアバター
Hello, I understand that your code encounters issues when the XML is incorrect or lengthy, leading to the code getting stuck. I can help you rectify this by optimizing the code to manage more connections efficiently. and I'll debug and refactor the code to handle XML parsing seamlessly, ensuring smooth execution even with lengthy or incorrect XML data. Let's discuss further to address your requirements and enhance the performance of your application. Best regards, Azad
€150 EUR 2日以内
5.0 (1 レビュー)
2.2
2.2
ユーザーアバター
According to your code, don't sound very difficult to solve it, i just will need some invalid xmls (large, incomplete and bad-formed) and some valid ones to perform tests and define an acceptance criteria (communication in english)
€75 EUR 4日以内
0.0 (0 レビュー)
0.0
0.0
ユーザーアバター
Buon giorno, sono un programmatore con diversi anni di esperienza in PHP. Dunque l'esigenza è di far accettare più connessioni contemporaneamente e di risolvere un problema con la ricezione di file troppo grandi. Ho capito bene?
€180 EUR 4日以内
0.0 (0 レビュー)
0.0
0.0
ユーザーアバター
Hi, I see your code is stuck when the XML is wrong or long or when the close tagID is not found. I can help with that. I have worked with PHP and XML parsing a lot. Money doesn't really matter for now. Please contact me and we'll try to solve the problem together. Best, Emiliau
€140 EUR 1日以内
0.0 (0 レビュー)
0.0
0.0
ユーザーアバター
Ciao, sarei interessato al tuo progetto e posso fornirti un risultato professionale a costi contenuti e in breve tempo. Se possibile contattami via chat così potremo discutere tutto più nel dettaglio e farti una proposta su misura. Renato
€150 EUR 20日以内
0.0 (0 レビュー)
0.0
0.0

クライアントについて

ITALYのフラグ
Pontecorvo, Italy
5.0
4
お支払い方法確認済み
メンバー登録日:7月 10, 2017

クライアント確認

ありがとうございます!無料クレジットを受け取るリンクをメールしました。
メールを送信中に問題が発生しました。もう一度お試しください。
登録ユーザー 投稿された仕事の合計
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
プレビューを読み込み中
位置情報へのアクセスが許可されました。
あなたのログインセッションの有効期限がきれ、ログアウトされました。もう一度ログインしてください。