I want to set a transient, but that transient to expire at midnight.
How can I calculate the time until midnight in PHP for use in that transient definition?
Do you just want this lines ?
$midnight_time = strtotime('tomorrow') - time();
set_transient( 'transient_name', $transient_datas, $midnight_time);
$midnight_time
represent the seconds before midnight happens.
You can ask your server to curl a page with a random parameter if you have cache to be sure your transient is consumed with a cronjob
.
strtotime("tomorrow")