As head of the city's prisons, Louis Giorla does not get much fan mail, especially from inmates.

But last week, a man in jail wrote to Giorla, thanking him for the holiday commissary bag of treats and toiletries given each inmate.

"I just wanted to thank you," the handwritten letter said. "It's difficult being incarcerated this time of year."

Giorla, 59, who will retire as commissioner next week, still has the note on his desk, in a nearly empty office where awards and pictures sit on the floor or in boxes.

"It was nice hearing not everyone feels oppressed," he said. "When it comes down to it, a jail is one group of people managing another. It's subject to personalities, resources, stresses, and circumstances that both sides create so you have to be able to listen to all the parties involved, find a balance."

Giorla, whose late father was a corrections officer, is a 33-year veteran of the Philadelphia prison system. When he started, politicians and policymakers were responding to high crime rates by pushing for harsher sentences - a strategy that has since shifted dramatically toward locking up fewer people and helping the formerly incarcerated find work.

Originally from South Philadelphia, Giorla once owned a lunch truck and had no interest in following his father's path. But when the economy went sour in the late 1970s, his father encouraged him to take the civil-service exam, and he became a corrections officer.

That was in 1982. Giorla moved up through the ranks to warden, and in 2008 Deputy Mayor Everett Gillison tapped him to be acting, then permanent, commissioner. This fall, he personally escorted Pope Francis into one of the city's prisons.

Giorla "was always a straight-shooter and he has always been a person that treated everyone with respect," Gillison said. "He's been a great partner, innovative and receptive."

During Giorla's eight years at the helm, the city's prison population - housed at six facilities in a complex in the Northeast, and a handful of satellite sites - swelled to 9,800, dipped to 7,500, spiked again, and is today about 7,500. The city has continually faced civil rights lawsuits on overcrowding.

"The biggest challenge facing any prisons commissioner in Philadelphia is the population," said Mike Resnick, director of public safety, who will become acting prisons director next week. "It drives everything you do up there, and the prison system and commissioner have absolutely no control over who comes and how long they stay."

In May, Philadelphia won a $150,000 MacArthur Foundation grant to study reducing its prison population. The city is up for a second grant in 2016.

But the jails remain overcrowded, with 75 percent of prisoners awaiting trial and the rest serving relatively short sentences. (Those facing longer sentences go to state prisons.) The 140-year-old House of Corrections stands in disrepair, said Giorla, who supported a bill to spend $7 million to buy land beside the current jail and build a new one. The bill was pulled back after opposition from neighbors and the City Planning Commission.

Mayor-elect Jim Kenney has said he has no interest in building a new prison.

"I still believe a replacement for that building will be needed," Giorla said. "Conditions aren't inhumane, but they're substandard, it looks like your movie vision of a prison."

If the new administration does not want to replace the House of Corrections, Giorla said, the goal should be to reduce the population enough that it can be shuttered.

He has told Kenney's transition team, which is looking nationally for Giorla's permanent replacement, that the key to his job is patience and a sense of humor.

"One minute, you're talking to someone who's lucid and logical, and the next, someone's telling you they're going to kill you, and then you walk to the third cell and someone's talking to themselves," Giorla said. "You have to adjust calmly to the situation, sometimes cell by cell."

Some inmates "would make Mother Teresa angry," he says. "Others, you just can't for the life of you figure out why they're here."

Usually, he said, those are the prisoners with mental illnesses or drug addictions.

"There are too many people in prison in the country because the mentally ill and substance addicted are not afforded the treatment opportunities they need," he said. "And so it's easier to send them here because we take everybody."

Giorla's worst days have made the news. In 2008 a prison gate fatally crushed a maintenance worker. Two years later a repeat offender escaped and killed a jeweler.

The successes are quieter - the new programs launched, the four times a year he recognizes staff members' achievements.

"Corrections officers have a chip on their shoulder," he said. "We're not exactly law enforcement, and we're not exactly social work." Balancing those roles can be difficult, he said, "but I think we've achieved a balance pretty well here."

When Giorla took over, 52 percent of sentenced inmates were enrolled in educational or vocational programs. Today the figure is 82 percent.

"He walked away leaving the system better than he found it," Resnick said. "The population is on a decline, we've expanded the myriad ways of getting programming and education to the inmates."

Giorla has plans - to go to Walt Disney World in February with his wife, three children, and six grandchildren. He hopes to travel a bit and "get out in the air."

He'll miss his staff. He'll even miss some inmates.

One prisoner who has been in the system four years writes to Giorla almost weekly to gripe, calling the conditions horrendous, the medical treatment unethical, the terms of his sentence unjust. He says Giorla, the mayor, and the district attorney all should be fired and jailed.

But people are full of surprises, said the exiting prisons chief, ever a believer in second chances.

"Oddly enough," Giorla said, "he sent me a Christmas card."

215-854-5506 @juliaterruso