simbiat/lodestone-parser

FFXIV Lodestone parser in PHP

1.1.18+20240716 2024-07-16 04:27 UTC

README

This project is PHP library for parsing data directly from the FFXIV Lodestone website initially based on one developed by @viion, but now completely rewritten. Previously was its branch.

The goal is to provide an extremely fast and lightweight library, it is built with the purpose of parsing as many characters as possible, key being: low memory, and micro-timed parsing methods.

Notes

  • This library parses the live Lodestone website. This website is based in Tokyo.
  • This library is built in PHP 8 minimum, please use the latest as this can increase

What's different?

This is what's different from original library from @viion:

  • It has different code structure, that aims at reduction of rarely used or unnecessary functions and some standardization.
  • Using regex instead of full HTML parsing for extra speed (and arrays instead of objects as result). It does not mean, that this will always be faster than using Symphony-based functions but will be true on average.
  • More filters for your search queries.
  • Return more potentially useful information where possible.
  • Attempt at multilingual support. Some filters even support actual "names" used on Lodestone (instead of just IDs).
  • Ability to "link" different types of entities, requesting several pages in one object. For example, you can get both Free Company and its members' details in same object.

Settings

It's possible to set your own UserAgent used by CURL: simply use ->setUseragent('useragent')

It's also possible to change LodeStone language by ->setLanguage('na'). Accepted language values are na, eu, jp, fr, de

It's possible to utilize Benchmarking to get parsing times for each iteration by ->setBenchmark(true)

Error handling

In the new concept fatal errors generally can happen only during HTTP requests. In order not to break "linking" function, they are handled softly in the code itself and are reported to ->errors and ->lasterror arrays. In essence, when an error occurs you will simply get an empty result for specific entity, and it will not be added to output.

To get last error you can use ->getLastError($close). For list of all errors - -getErrors($close). $close is an expected boolean, that, if set to true, will close the cURL handle. It is set to false by default, based on assumption, that you are using these only for some kind of validation.

All pages

All parsers accepting page number support value of 0, which will return all pages (that is run the respective parser recursively). Default value for page is set to 1 to limit resources used.

Test script

There is a \Simbiat\LodestoneTest class to test run all the available functions in some general scenarios. Run it to get samples of output formatting and timings for each type of test in a table format. Note, that the last 2 tests are 'error tests', so their results are purposefully reversed for the report's consistency. Additionally, achievements' test is purposefully ran with details set to true and Free Company members in All pages mode, because of this their benchmark results will be presented as list of timings.

Getting results

To get results of parsers (listed below) you need to run ->getResult($close), which will return the array with the results. $close is an expected boolean, that, if set to true, will close the cURL handle. It is set to true by default, based on assumption, that getting results will be your last action.

NOTICE: if you are not calling ->getResult($close) at all or are calling it only with false, it's recommended to explicitly unset the object you are using, unless you are using to free up resources.

Parsers