Multiple police officers have been injured after an active gunman fired at them in an ongoing shooting.

A gunman who opened fire on police as they were serving a drug warrant in Philadelphia, wounding six officers triggering a standoff that extended into the night, is in police custody.

Philadelphia Police Sergeant Eric Gripp said early Thursday morning that the man was taken into custody after an hours-long standoff with police.

The shooting began about 4.30pm as officers went to a home in a north Philadelphia neighbourhood of brick and stone terraces to serve a narcotics warrant in an operation “that went awry almost immediately,” Philadelphia Police Commissioner Richard Ross said.

Many officers “had to escape through windows and doors to get (away) from a barrage of bullets”, Commissioner Ross said.

The six officers who were struck by gunfire have been released from hospitals, Sergeant Gripp said.

Two other officers were trapped inside the house for about five hours after the shooting broke out but were freed by a SWAT team well after darkness fell on the residential neighbourhood. Three people that officers had taken into custody in the house before the shooting started were also safely evacuated. “It’s nothing short of a miracle that we don’t have multiple officers killed today,” Commissioner Ross said.

Authorities were attempting to communicate with the gunman for more than five hours after he opened fire in the Nicetown-Tioga neighbourhood, in the city’s north.

In his most recent update, Sergeant Gripp said two officers and additional prisoners who were inside the house with the shooter have now been safely evacuated, but added the situation remains active.

Earlier, he said several officers had been injured and warned people to avoid the area while the shooting was ongoing.

.@PPDCommish Ross: the officers and additional prisoners that were inside of the house with the shooter were safely evacuated. The shooter remains armed inside — Eric Gripp (@PPDEricGripp) August 15, 2019

Shooting incident 3700 N 15th Street. Suspect/(s) firing at police. Large police presence. AVOID AREA — Eric Gripp (@PPDEricGripp) August 14, 2019

Police said one officer was struck in the head but was conscious and communicating. A second was hit in one or both arms. The injuries of the others are unknown.

According to local reports, the incident began when officers attempted to serve a warrant at a house in the Nicetown-Tioga section of the city and were met with gunfire.

The suspect barricaded himself inside a building, and about a dozen officers took cover behind cars as officials surrounded a home with guns drawn, ABC News reported.

Police made contact with him over the phone, but he did not speak.

Commissioner Ross told reporters the gunman suddenly opened fire when officers were in the home’s kitchen.

“Many of them had to escape through windows and doors,” he said.

The shooter had continued to fire out of the windows, the commissioner said.

commissioner Ross said attempts to contact the shooter have so far been unsuccessful. “We are trying to talk to this male, trying to let him know that he can end this peacefully now,” he told reporters.

SWAT officers were reportedly able to escort four women out of the building where the shooter was barricaded.

CNN affiliate KYW reporter Greg Argos, who was on the scene, described the women as “visibly upset, crying, as they were escorted down the street”.

One woman told the outlet she heard over 100 gunshots and saw people running for their lives. “I heard so many gunshots … I’m scared,” she said.

Another neighbourhood resident likened the scene to a war. “It was like a war — like a scene that you see in war,” she told NBC. “The guns, the fire, the noise — it was like bombs going off simultaneously at a time where people are having dinner.”

Live video from news stations shows a huge police presence in the neighbourhood, with dozens of police cars and officers at the scene.

The injured officers have been taken to temple University Hospital, with wounds believed to be non-life threatening.

Another officer was injured by a crash at the scene.

Temple University put itself on partial lockdown, urging people to seek shelter and remain cautious.

Lockdown is in effect for Health Sciences Center Campus. Seek shelter. Secure doors. Be silent. Be still. Police are responding. — Temple University (@TempleUniv) August 14, 2019

President Donald Trump has been briefed on the shooting according to the White House.

On Twitter, former Vice President Joe Biden said he and his wife “send our prayers to the police officers injured today in Philadelphia, and to their families who wake up every day knowing their loved ones are walking into harm’s way when they put on a badge”.

Likewise, Democratic presidential candidate Beto O’Rourke said the incident is “a reminder of what police officers across America to serve their communities every day”.

“Thinking of Philadelphia, and everyone impacted by this gun violence epidemic we need to end,” he wrote.