Hi,

Is there any tool or library in php which uses mediawiki api, to get
the photos and meta data from commons?

Most metadata are not exposed by the API, but they are machine readable too [1]

This Wordpress plugin (written in PHP) makes use of that. [2]

[1] <https://commons.wikimedia.org/wiki/Commons:Machine-readable_data>
[2] <https://www.mediawiki.org/wiki/Wikimedia_Commons_on_Wordpress>
 
Hope that helps,
--
Jean-Frédéric