I don't really know PHP but I guess you need to mimic what the REST API is expecting. Paginate search results | Elasticsearch Guide [8.13] | Elastic
Could you try and may be share the code you wrote and the problem you are facing?
Please read this about how to format.