Find Jobs
Hire Freelancers

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

€30-250 EUR

Zaprt
Objavljeno pred 14 dnevi

€30-250 EUR

Plačilo ob dostavi
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 projekta: 38067333

Več o projektu

7 ponudb
Projekt na daljavo
Aktivno pred 7 dnevi

Želite zaslužiti?

Prednosti oddajanja ponudb na Freelancerju

Nastavite svoj proračun in časovni okvir
Prejmite plačilo za svoje delo
Povzetek predloga
Registracija in oddajanje ponudb sta brezplačna
7 freelancerjev je oddalo ponudbo s povprečno vrednostjo €128 EUR za to delo
Avatar uporabnika
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 v 7 dneh
4,9 (5 ocen)
3,9
3,9
Avatar uporabnika
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 v 2 dneh
5,0 (1 ocena)
2,2
2,2
Avatar uporabnika
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 v 4 dneh
0,0 (0 ocen)
0,0
0,0
Avatar uporabnika
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 v 4 dneh
0,0 (0 ocen)
0,0
0,0
Avatar uporabnika
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 v 1 dnevu
0,0 (0 ocen)
0,0
0,0
Avatar uporabnika
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 v 20 dneh
0,0 (0 ocen)
0,0
0,0

O stranki

Zastava ITALY
Pontecorvo, Italy
5,0
4
Plačilna metoda je verificirana
Član(ica) od jul. 10, 2017

Verifikacija stranke

Hvala! Po e-pošti smo vam poslali povezavo za prevzem brezplačnega dobropisa.
Pri pošiljanju vašega e-sporočila je šlo nekaj narobe. Poskusite znova.
Registrirani uporabniki Skupaj objavljenih del
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Nalaganje predogleda
Geolociranje je bilo dovoljeno.
Vaša prijavna seja je potekla, zato ste bili odjavljeni. Prosimo, da se znova prijavite.