Find Jobs
Hire Freelancers

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

€30-250 EUR

Mbyllur
Postuar 14 days ago

€30-250 EUR

Paguhet në dorëzim
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 e Projektit: 38067333

Rreth projektit

7 propozime
Projekt në distancë
Aktive 8 days ago

Po kërkoni të fitoni para?

Përfitimet e ofertës për Freelancer

Vendosni buxhetin dhe afatin tuaj
Paguhuni për punën tuaj
Përshkruani propozimin tuaj
Është falas të regjistrohesh dhe të bësh oferta për punë
7 profesionistët e pavarur ofrojnë mesatarisht €128 EUR oferta për këtë punë
Avatari i Përdoruesit
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 në 7 ditë
4,9 (5 përshtypje)
3,9
3,9
Avatari i Përdoruesit
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 në 2 ditë
5,0 (1 review)
2,2
2,2
Avatari i Përdoruesit
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 në 4 ditë
0,0 (0 përshtypje)
0,0
0,0
Avatari i Përdoruesit
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 në 4 ditë
0,0 (0 përshtypje)
0,0
0,0
Avatari i Përdoruesit
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 në 1 ditë
0,0 (0 përshtypje)
0,0
0,0
Avatari i Përdoruesit
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 në 20 ditë
0,0 (0 përshtypje)
0,0
0,0

Rreth klientit

Flamuri i ITALY
Pontecorvo, Italy
5,0
4
Mënyra e pagesës u verifikua
Anëtar që nga korr 10, 2017

Verifikimi i klientit

Faleminderit! Ne ju kemi dërguar me email një lidhje për të kërkuar kredinë tuaj falas.
Ndodhi një gabim gjatë dërgimit të email-it tuaj. Ju lutemi provoni përsëri.
Përdorues të regjistruar Punë të postuara
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Po ngarkohet shikimi paraprak
Leja u dha për Geolocation.
Seanca e hyrjes ka skaduar dhe ke dalë. Hyr sërish.