I’m not a PHP guy so I can’t offer much help, I’ll leave it to others with more PHP experience to offer advice.
All I can see from a brief glance is that I don’t understand why you’re setting the Accept: application/vnd.twitchtv.v3+json header. that’s not needed. The Refresh Access Token docs don’t require setting any additional headers, just the specified querystring params.