Rocker Pete Doherty pleaded guilty to a drug charge, after arriving so late that the judge had issued an arrest warrant.
The judge warned Doherty that he had one last chance to avoid prison.
Doherty, who arrived in court at midday, also pleaded guilty to failing to appear on time at 9:30 a.m. without a reasonable excuse.
The 28-year-old lead singer of Babyshambles admitted possessing quantities of crack cocaine, heroin, cannabis and ketamine as well as to two driving offenses on May 5.
Lachhar deferred sentence to Aug. 7 on condition that the singer enter a detoxification program on July 16, as he said he was willing to do.
"If you go to this place to have detox and take advantage of it then we will see what sentence is appropriate when you next come, but if you do not I can tell you now that you will go into custody," Lachhar told him.
It's rehab or jail," Doherty told reporters as he left. "I was going to rehab anyway, to be honest with you, but this is a little push."
Doherty, best known as the boyfriend of supermodel Kate Moss, has been undergoing drug treatment under court order because of previous convictions.
His lawyer, Sean Curran, was summoned to court twice to explain his client's whereabouts before the judge's patience ran out.
"This is a court of law. He should have been here at 9:30 and he wasn't so I am issuing a warrant with no bail," she said.
Curran told the judge that Doherty had "a difficulty in his personal life which led to him being caught in this situation where he was driving the vehicle" but did not elaborate.
The lawyer said it would be in Doherty's best interest not to drive, but the judge interrupted: "I am more concerned about the danger to other members of the public on the road and to pedestrians."