It’s been five years, eight months and four days since Dr. William Petit’s life was destroyed by the Connecticut home invasion that shocked the nation.

He still counts the days. But now he’s building a new life and slowly putting his nightmares behind him.

Petit, who lost his wife and two daughters in the horrific attack, has remarried.

Now 56, he met Christine Palauf while she was working for the Farmington Country Club. The two became close after she began working for the foundation he created in memory of his family.

Christine provided Petit with the emotional support that enabled him to deal with his nightmares, he’s said. They were married last year in a tearful wedding attended by some 300 friends and relatives.

Petit told Esquire magazine that following the July 2007 attack, he used to be jarred awake each night at the hour when two lowlifes, Steven Hayes and Joshua Komisarjevsky, raided his home, beat him unconscious and slaughtered his wife and children.

“In the beginning, when I couldn’t sleep, it was always that night,” he said. “I’d bolt awake at 3 a.m. just like clockwork, no matter what.”

He would visualize the killers’ faces.

Gradually, he was able to sleep later.

“And then it sorta switched to mornings,” he said. “The mornings got bad. It would always be right in front of me. Right in front of your face.”

Now, Petit said, he can sleep up to five hours. But he still keeps the lights on in the living room all night.

“You do what you have to do,” he told Esquire. “You just keep going.”

Petit has never returned to the site of his former home, which burned down after the thugs torched it — and upon which neighbors created a memorial garden.

His memories are too painful, he says. The home was targeted by Hayes and Komisarjevsky for an invasion that was supposed to be a quick robbery, but spiraled into a horror story that lasted seven hours.

When it was over, Petit’s wife of 18 years, Jennifer, was dead, as were daughters Hayley, 17, and Michaela, 11. Petit, who had escaped during the carnage, gave up practicing medicine and devoted himself to the family foundation, which aids victims of violence and chronic illness and helps with the education of young people.

As its Web site puts it: “The Petit Family Foundation tries to do as many good actions as possible to counteract the evil that truly exists in the world today.”

The story of the Petit family and Petit’s life afterward touched people around the world, and Petit received 25,000 letters.

Petit said he was heartened by three young brothers who ask friends attending their birthday parties each year not to buy presents for them but to send donations to the foundation instead.

Hayes and Komisarjevsky, who fled in Petit’s car, only got a short distance before they were caught. Petit had to deal with their trials, in 2010 and 2011.

Christine remained Petit’s emotional rock throughout the ordeal, which ended with the killers being sentenced to death.