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;
รหัสโปรเจกต์: 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
ยืนยันวิธีการชำระเงินแล้ว
เป็นสมาชิกตั้งแต่ ก.ค. 10, 2017

การยืนยันลูกค้า

ขอบคุณ! เราได้ส่งลิงก์สำหรับเครดิตฟรีให้คุณทางอีเมลแล้ว
เกิดข้อผิดพลาดขณะส่งอีเมลของคุณ กรุณาลองอีกครั้ง
โลโก้ Freelancer Thailand / ภาษาไทย ช่วยเหลือและสนับสนุน FreelancerประเภทโปรเจคการประกวดFreelancerองค์กรแพ็กเกจสมาชิกโครงการ Freelancer ชั้นแนวหน้าการจัดการโปรเจคงานในพื้นที่Photo Anywhereหน้าจัดแสดงผลงานAPI สำหรับนักพัฒนาได้รับการยืนยันDesktop App เกี่ยวกับเกี่ยวกับเราวิธีใช้งานความปลอดภัยนักลงทุนแผนผังเว็บไซต์เรื่องราวข่าวออกสื่อทีมรางวัลข่าวประชาสัมพันธ์ร่วมงานกับเรา ข้อกำหนดนโยบายความเป็นส่วนตัวข้อกำหนดและเงื่อนไขนโยบายลิขสิทธิ์ข้อพึงปฏิบัติค่าธรรมเนียมและค่าบริการหุ้นส่วนEscrow.comLoadshiftWarrior Forum แอปโลโก้ Apple App Store โลโก้ Google Play
ไม่สามารถคัดลอกไปยังคลิปบอร์ดได้ โปรดลองอีกครั้งหลังปรับเปลี่ยนการอนุญาต
คัดลอกไปยังคลิปบอร์ดแล้ว
ผู้ใช้ที่ลงทะเบียน งานที่มีการโพสต์ทั้งหมด
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
กำลังโหลดตัวอย่าง
ได้รับอนุญาตสำหรับตำแหน่งทางภูมิศาสตร์
เซสชั่นการเข้าสู่ระบบของคุณหมดอายุและคุณได้ออกจากระบบแล้ว กรุณาเข้าสู่ระบบอีกครั้ง