American fuel makers are posting their best second-quarter profits in years, thanks to soaring domestic oil production and regional pipeline bottlenecks that are allowing them to buy crude on the cheap.

Refining companies typically suffer as oil prices rise because drivers scale back their travel, reducing demand for gasoline and diesel. But record U.S. production, coupled with insufficient pipeline capacity in Canada and West Texas, has depressed the cost of oil in many parts of the country, even as oil prices have been rising in general.

That has boosted margins for many stand-alone refiners, propelling some, including Phillips 66 and Marathon Petroleum Corp. , to their highest second-quarter profits on record.

Phillips 66, the largest independent refiner by market capitalization, earned an average of $12.28 per refined barrel during the second quarter, up from $8.44 for the comparable period last year. The company reported profit of $1.3 billion, up 143% from 2017’s second quarter.

Marathon Petroleum earned $15.40 per refined barrel, compared with $11.32 a barrel in the year-earlier period. Its second-quarter profit rose 118% to $1.1 billion.