Jump to content


  • Content Count

  • Joined

  • Last visited

Community Reputation

0 Neutral

About Lectrician

  • Rank

Profile Information

  • Gender
    Not Telling
  1. Lectrician

    Sorting Multi Array

    That's great, thank-you. I had kind of got there, but kept trying this and wondered why it would not work: <<INCORRECT CODE>> uasort($usersdata, function($1, $2) { return strcasecmp($1, $2); }); I also left my asort un-commented directy below the new code, so the new code was doing it's job, and then the asort was obliterating it's work! Twit.
  2. Lectrician

    Sorting Multi Array

    I have an array as below, and would like to sort it alphabetically by username. I know in the order shown below, asort works, but what if the username key is not the first? Any ideas on the best ways? Thanks :-) usersdata = array( [12345] = array( [username] => "Toby", => "toby@toby.com", [permissions] => "1,2,3,4" ) [12346] = array( [username] => "Tom", => "tom@tom.com", [permissions] => "5,6,7,8" ) [12347] = array( [username] => "Mable", => "mable@olddear.com", [permissions] => "1,2,3,4" ) [12348] = array( [username] => "Twit", => "twit@twit.com", [permissions] => "1,2,3,4,5,6,7" ) )
  3. Lectrician

    File Handles

    Ok. I am asking some basic type questions I guess! When you open a file with a filehandle, is it safe to use the same file handle a couple times in a script, for different files, assuming one is closed before the other opened? I use $fh a lot in my scripts, and wonder if this is bad practice? I copy and paste code quite often to speed up my writing, and retain this filehandle usually.
  4. Lectrician

    Opening a file - memory used

    Hi, yes, PFsense is a firewall, and clients connect to it, receiving an IP by DHCP from it. PFsense is able to read the MAC and HOSTNAME, and use these to identify a user uniquely. Obviously they could be spoofed. I have not run into issues opening the files to search yet. They are not huge. No errors are reported. I was just wondering on the best method. Opening the file in chunks may be the best option. Thanks.
  5. Lectrician

    Flock - Queing

    So if I do: If(flock($file, LOCK_EX)){ Play with file } What happens if a file is already locked. Will it wait, or just pass this code completely?
  6. Lectrician

    Opening a file - memory used

    Thanks. Yes, the line for each user looks like this: timestamp | name | email | postcode | IP given | their MAC | hostname | HTTP header | a few other bits of info There can be 400 odd lines on busy days. I am running PFsense, and using the captive portal in it, altering the PHP to suit me. I check to make sure no cookie exists holding the name, email, postcode (these are auto-filled into the HTTP form fields when they go to connect). If no cookie exists, I open yesterdays logs, search each line for the users MAC address, and then auto fill. I think it is safe to assume the MACs wil be different, as this is how PFsense deals with identifying users. If yesterdays logs don't find a match, the script will go back 30 days. This whole searching the logs could be omitted, but it is preferred to have the form fields auto-filled, as customers are less annoyed! I am not sure I can setup a database on PFsense - I would need to have a look. Everything else on my version of PFsense runs as a flat file system. Newer versions do use an SQL database.
  7. Lectrician

    Flock - Queing

    Thanks. I am going to remove the IF statement to force all runs of the script to take action on the file. As it stands at the moment, if a lock is not obtained, the script does not take any action on the file. Thanks.
  8. Lectrician

    Opening a file - memory used

    Thanks. I was looking at two different scenarios. I have a log file which is appended and rotated daily. I can't alter how this written. Every night, my PHP script runs to extract data from each line. The files have become too large to open in one go into an array, so I altered the script to open the file and extract data line by line, using similar code to above(thanks). This now works fine. It got me to thinking. I have a log file which I append to, as users pass through a captive portal. It stores a users MAC, IP, HOSTNAME, HTTP HEADER, NAME, POSTCODE, EMAIL etc on a line. The file can be upto 400 lines long sometimes. When a user is presented with the captive portal, if they have passed through before, their data is auto filled. Their cookies are checked first, but if these have been cleared, up to 30 days of log files are opened, each line being checked for the users MAC. If a match is found, their details are auto filled. I can't decide if its best to open a whole log file into an array and work through each entry, or open the file line by line. This is where my speed vs memory query came from. I want it done quickly, but don't want to kill the process due to lack of memory (don't think it has ever died from lack of memory yet). Cheers.
  9. Lectrician

    Flock - Queing

    Hi. If I use Flock to lock a file once open, when other people run the script (visit webpage), will they queue in turn to access the file, eventually being able to access it? Is there a time out? I have been using an IF argument, so if no lock is made, the script continues. Looking at my code, this is undesirable. I would prefer the script to wait until the script can use the file. There are times when several people may be trying to access the same file - The script should run and complete in seconds. Thanks.
  10. Lectrician

    Opening a file - memory used

    Hi. I am working with some rather large files. Sometimes I am just opening a file and trying to find an entry on a single line. Sometimes I am opening a file and working on each line. Whats the most efficient way to work with a large file? If I open a file, and place all lines into an array, I will use a lot of memory. If I open a file, and work on it line by line, I should use much less memory, but will the process take longer? Whats most efficient? I have underlined my main question above. Thanks :-)

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.