Find Jobs
Hire Freelancers

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

€30-250 EUR

Ditutup
Disiarkan 17 hari yang lalu

€30-250 EUR

Dibayar semasa penghantaran
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 Projek: 38067333

Tentang projek

7 cadangan
Projek jarak jauh
Aktif 11 hari yang lalu

Ingin menjana wang?

Faedah membida di Freelancer

Tetapkan bajet dan garis masa anda
Dapatkan bayaran untuk kerja anda
Tuliskan cadangan anda
Ianya percuma untuk mendaftar dan membida pekerjaan
7 pekerja bebas membida secara purata €128 EUR untuk pekerjaan ini
Avatar Pengguna
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 dalam 7 hari
4.9 (5 ulasan)
3.9
3.9
Avatar Pengguna
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 dalam 2 hari
5.0 (1 ulasan)
2.2
2.2
Avatar Pengguna
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 dalam 4 hari
0.0 (0 ulasan)
0.0
0.0
Avatar Pengguna
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 dalam 4 hari
0.0 (0 ulasan)
0.0
0.0
Avatar Pengguna
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 dalam 1 hari
0.0 (0 ulasan)
0.0
0.0
Avatar Pengguna
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 dalam 20 hari
0.0 (0 ulasan)
0.0
0.0

Tentang klien

Bendera ITALY
Pontecorvo, Italy
5.0
4
Kaedah pembayaran disahkan
Ahli sejak Jul 10, 2017

Pengesahan Klien

Terima kasih! Kami telah menghantar pautan melalui e-mel kepada anda untuk menuntut kredit percuma anda.
Sesuatu telah berlaku semasa menghantar e-mel anda. Sila cuba lagi.
Pengguna Berdaftar Jumlah Pekerjaan Disiarkan
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Memuatkan pratonton
Kebenaran diberikan untuk Geolocation.
Sesi log masuk anda telah luput dan telah dilog keluar. Sila log masuk sekali lagi.