Search code examples
phpsecuritytokenaccess-token

Save token as file


i would like to ask if is ok to save authorization token as a file in the specific folder. Or will be faster with every request connect to database and compare with token save in the table ? Thanks for answer


Solution

  • From the "what's faster" standpoint...

    Accessing, writing and reading files on the hard disk has its overhead and bears - compared to accessing memory - some performance loss. Databases (again, typically) also store their data on the hard disk, but also often keep data loaded in memory. That's because accessing memory is much faster than accessing files on a hard drive.

    So, if you're asking...

    What's faster?

    The answer would be (most of the times): Database.

    And does it really matter?

    Depends on your application.

    • If you're having five requests per second reading your access tokens, then: no, it doesn't matter, and storing them on the disk is - performance wise - absolutely enough.
    • If you need to read access tokens (tens, hundreds of) thousands of times per second, then using a database might be a slightly better (faster) option for you.