Skip to content

Instantly share code, notes, and snippets.

@slava-konashkov
Last active July 26, 2021 18:12
Show Gist options
  • Save slava-konashkov/9f213d196f3c68ccbd6c5d879f4d4734 to your computer and use it in GitHub Desktop.
Save slava-konashkov/9f213d196f3c68ccbd6c5d879f4d4734 to your computer and use it in GitHub Desktop.
PHP regex Apache access log
$regex = '/^(?P<IP>\S+)
\ (?P<ident>\S)
\ (?P<auth_user>.*?) # Spaces are allowed here, can be empty.
\ (?P<date>\[[^]]+\])
\ "(?P<http_start_line>.+ .+)" # At least one space: HTTP 0.9
\ (?P<status_code>[0-9]+) # Status code is _always_ an integer
\ (?P<response_size>(?:[0-9]+|-)) # Response size can be -
\ "(?P<referrer>.*)" # Referrer can contains everything: its just a header
\ "(?P<user_agent>.*)"$/xU';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment