Jump to content

agravayne

Members
  • Posts

    26
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

agravayne's Achievements

Member

Member (2/5)

0

Reputation

  1. set_time_limit is for the whole script. I don't want the script to ever timeout -its a socket server and should never die, it shoudl just wait for data on the socket re my loop and if it does not get anything after a set time then just move on.
  2. Hello, I don't actually want to end the script I want the script to move on after a set amount of time. Just want the while loop to timeout. Scott
  3. Hello All, I have a while loop that reads data from a socket until it reaches a specified teminator. This works but I need to be able to time this out so that if the terminator is for some reason omitted then the while loop won't wait forever. I have tried adding a incremental counter but this only ever gets up to one - whether it reads or not. Here is my code. while(substr($clients[$i]['Data'], strlen($clients[$i]['Data'])-4, 4)!="TS:\n") { if(false!== ($data = socket_recv($tempsock, $buf,10240,0))); {$clients[$i]['Data'].=$buf;} } Any ideas Thanks
  4. Hello, I have a table with the following structure CREATE TABLE `tmxdata` ( `ID` int(11) NOT NULL auto_increment, `ESN` bigint(20) NOT NULL, `Type` int(11) NOT NULL, `Value` varchar(255) default NULL, `Timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP, `EventTime` datetime NOT NULL, `Processed` enum('Y','N') NOT NULL default 'N', PRIMARY KEY (`ID`) ) ENGINE=MyISAM AUTO_INCREMENT=32 DEFAULT CHARSET=latin1; I want to try and get the last entry by eventtime for each ESN and Type. Currently I am using a complicated query joining on the same table SELECT speedtable.ESN, speedtable.Type, speedtable.Value as speed, max(speedtable.EventTime), headtable.Type, headtable.Value as heading, max(headtable.EventTime), celltable.Type, celltable.Value as cellid, max(celltable.EventTime), sigtable.Type, sigtable.Value as signalstrength, max(sigtable.EventTime), igtable.Type, igtable.Value as ignition, max(igtable.EventTime), volt1.Type, volt1.Value as volt1contact, max(volt1.EventTime), volt2.Type, volt2.Value as volt2contact, max(volt2.EventTime), tempr.Type, tempr.Value as temperature, max(tempr.EventTime), tempr2.Type, tempr2.Value as tempalarm, max(tempr2.EventTime), batt.Type, batt.Value as battery, max(batt.EventTime), batt2.Type, batt2.Value as battalarm, max(batt2.EventTime) FROM ((((((((((tmxdata as speedtable right join tmxdata as headtable on speedtable.ESN=headtable.ESN) right join tmxdata as celltable on speedtable.ESN=celltable.ESN) right join tmxdata as sigtable on speedtable.ESN=sigtable.ESN) right join tmxdata as igtable on speedtable.ESN=igtable.ESN) right join tmxdata as volt1 on speedtable.ESN=volt1.ESN) right join tmxdata as volt2 on speedtable.ESN=volt2.ESN) right join tmxdata as tempr on speedtable.ESN=tempr.ESN) right join tmxdata as tempr2 on speedtable.ESN=tempr2.ESN) right join tmxdata as batt on speedtable.ESN=batt.ESN) right join tmxdata as batt2 on speedtable.ESN=batt2.ESN) where speedtable.Type=2 and headtable.Type=4 and celltable.Type=17 and sigtable.Type=18 and igtable.Type=33 and volt1.type=34 and volt2.type=36 and tempr.type=49 and tempr2.type=50 and batt.type=52 and batt2.type=56 group by speedtable.ESN Howerer this is slow and is missing some entries.. Is there a better way to do this? Here is a bit of sample data. 92,353358016023678,36,"01","2009-10-27 12:23:51","2009-10-27 12:23:51","N" 93,353358016023678,2,"0.51,5.86","2009-10-27 14:08:52","2009-10-27 14:08:50","N" 94,353358016023678,4,"N,0.07624,1.77241","2009-10-27 14:08:52","2009-10-27 14:08:50","N" 95,353358016023678,17,"33443442","2009-10-27 14:08:52","2009-10-27 14:08:50","N" 96,353358016023678,18," 11","2009-10-27 14:08:52","2009-10-27 14:08:50","N" 97,353358016023678,33,"01","2009-10-27 14:08:52","2009-10-27 14:08:50","N" 98,353358016023678,34,"01","2009-10-27 14:08:52","2009-10-27 14:08:50","N" 99,353358016023678,36,"01","2009-10-27 14:08:52","2009-10-27 14:08:50","N" 100,353358016023678,49,"24","2009-10-27 14:08:52","2009-10-27 14:08:50","N" 101,353358016023678,50,"100","2009-10-27 14:08:52","2009-10-27 14:08:50","N" 102,353358016023678,2,"0.51,5.86","2009-10-27 14:11:44","2009-10-27 14:11:44","N" 103,353358016023678,4,"N,0.07624,1.77241","2009-10-27 14:11:44","2009-10-27 14:11:44","N" 104,353358016023678,17,"33443442","2009-10-27 14:11:44","2009-10-27 14:11:44","N" 105,353358016023678,18," 11","2009-10-27 14:11:44","2009-10-27 14:11:44","N" 106,353358016023678,33,"01","2009-10-27 14:11:44","2009-10-27 14:11:44","N" 107,353358016023678,34,"01","2009-10-27 14:11:44","2009-10-27 14:11:44","N" 108,353358016023678,36,"01","2009-10-27 14:11:44","2009-10-27 14:11:44","N" 109,353358016023678,49,"24","2009-10-27 14:11:44","2009-10-27 14:11:44","N" 110,353358016023678,50,"100","2009-10-27 14:11:44","2009-10-27 14:11:44","N" 111,353358016023678,52,"60000","2009-10-27 14:11:44","2009-10-27 14:11:44","N" 112,353358016023678,56,"100","2009-10-27 14:11:44","2009-10-27 14:11:44","N" 113,899999,2,"0.51,5.86","2009-10-27 14:24:46","2009-10-27 14:24:46","N" 114,899999,4,"N,0.07624,1.77241","2009-10-27 14:24:46","2009-10-27 14:24:46","N" 115,899999,17,"33443442","2009-10-27 14:24:46","2009-10-27 14:24:46","N" 116,899999,18," 11","2009-10-27 14:24:46","2009-10-27 14:24:46","N" 117,899999,33,"01","2009-10-27 14:24:46","2009-10-27 14:24:46","N" 118,899999,34,"01","2009-10-27 14:24:46","2009-10-27 14:24:46","N" 119,899999,36,"01","2009-10-27 14:24:46","2009-10-27 14:24:46","N" 120,899999,49,"24","2009-10-27 14:24:46","2009-10-27 14:24:46","N" 121,899999,50,"100","2009-10-27 14:24:46","2009-10-27 14:24:46","N" 122,899999,52,"60000","2009-10-27 14:24:46","2009-10-27 14:24:46","N" 123,899999,56,"100","2009-10-27 14:24:46","2009-10-27 14:24:46","N" 124,899999,2,"0.51,5.86","2009-10-27 14:41:16","2009-10-27 14:41:16","N" 125,899999,17,"33443442","2009-10-27 14:41:16","2009-10-27 14:41:16","N" 126,899999,18," 11","2009-10-27 14:41:16","2009-10-27 14:41:16","N" 127,899999,33,"01","2009-10-27 14:41:16","2009-10-27 14:41:16","N" Thanks Scott
  5. Hello, I am trying to deal with binary data - and am completely new to this - via PHP. What I am doing is emulating a device that will post to a socket server. I have a client page that emulates the device and a listening server that deals with data posted to it. What I have need to do in order to emulate this is create some binary data and post it - then read the binary data back in and deal with it appropriately. Any ideas? I though about creating a file on the client side then reading that file in on the receiving side - but not sure how to create a binary file? Any pointers? Scott
  6. Except that we are getting charged per 100k of bandwidth and will have 6000 messages per minute so we want to keep the overhead as low as possible to keep costs down. What's the overhead for lighthttpd
  7. We will need to send back confirmation of the message being deleivered. ON top of that we may also want to end new instructions to the client in order to reprogram it. I understand this can be done with UDP on the application side - just trying to weigh up if the saving in overhead is worth it.
  8. Many thanks for all this. does anyone know a resource for comparing packet sizes? We will be sending very small messages - approx 9bytes so we want to use the most efficient way. From what I understand a HTTP packet will be around 300 bytes before there is any data - thus our reasoning is to use sockets. Does anyone know the rough size of a standard TCP/IP packet in comparison and a UDP packet?
  9. Hello, Not sure if this is the correct place to post this as it kind of fits everywhere! lol Anyway, we are designing a new piece of hardware that will send messages to our server. The question I have is whether we send the messages vie http to a PHP page or use sockets - possibly having a php listening socket. I am trying to find information on which way is the best way to go - all I can find are some sockets tutorials but these don't really answer the question as to which is best. The problem we are anticipating the the volume - the messages are very small 9 bytes on average but there will eventually be many of them. They cold grow to 6000 a minute. We don't want to put a strain on the web server by receiving all these messages and at the same time serving web pages to the clients. Also we are being charged a network charge for bandwidth. My thinking that the packages sent on Http would be larger due to the header information? But has anyone got any idea how much larger? Can anyone think of any dire reasons not to go with a socket approach? We are running a LAMP server on Cent OS. Many thanks Scott Bailey
  10. Hello, Is it possible in PHP to check wether a page has a parent? I have a site that uses iframes in certain parts. The site has a timeout so after a certain time if left when the user clicks in one of the iframes it times out and takes them to the homepage - but that appears within the iframe! What I need it to do is detect that its in an Iframe and if so refresh the parent not the child. This is the function that checks. function CheckLogin() { if(!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] != "LoggedIn") header("Location: http://www.url.com/"); } So could I adapt this? Many thanks Scott
  11. Hello All, I was wondering if the following is possible. I have a page that is makeing several large sql queries and dropping them into arrays but much of the data is duplicated so what I would rather do is drop all the data into one large array them create smaller arays on the fly as they are needed from this. Here is a simple example. The larger array would contain the following keys - Serial Number, Type, Group, Name I would then for example need to create an array of all the different distinct group names. So for example this would result in Group1, Group2 etc. I would them for each of these loop back though the large array and get al the serial numbers accociated with each group. So all serials nubers whose group is Group1. Firstly I cannot see how to create the sub array of groups. Secondly how would I do the search in the array. It wouuld be the equivalent of a sql query select * from array where Group=Group1 if you see what I mean. Secondly - would using arrays like this be significantly faster than the multiple queries I am now using? Hope this is clear. Scott
  12. Hello All, Not sure of this is possible but I need to create a table with an autoincrement to a specific format. it shuld be 10 didgits ling and start with 03. I could just start the autoincremet at 300000000 but of course there's no leading zero. Has anyone got any ideas? Scott
  13. Hello All, Have some strange behaviour happening. We recently moved our mysql from mac-osx to centos and everything works fine except the auto-increment keys are now incrementing by a factor of 10 instead of 1. Has anyone got any ideas why or where this can be set properly? Many thanks Scott
  14. mmm I can check the session variable and if its not there prevent a write to the database. That would solve this problem. The original page was far more complicated but what I have posted here is a stripped down version and still has the same problem. Originally I had a query that would check that the $_POST['txn_id'] did not already exist in the database if it did to prevent the insert. However it still wrote twice. I will try checking the session variable first though.
  15. The query $sql3=mysql_query("select * from indCredits where MemberID=$MemberID"); returns one row. Which is correct.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.