Delay
Make a commitment that no matter what, you won’t act on an urge right away. Instead you’ll wait at least 20 minutes (or some other amount of time). Hopefully, by then the urge will have passed. If you want to use this technique, decide how many minutes you are ready to wait, and add it to your plan.
Even if you ended up watching porn or masturbating after 20 minutes, congratulate for at least sticking to your plan! You’re still better off than if you have done it right away. By refusing to gratify yourself instantly, you have strengthened your self-control muscles which is good for your long term success. If this happens repeatedly, try increasing the number of minutes, until you find the amount of time that works best for you. It’s also possible that your urges last longer than usual because your actively focusing on it (e.g. fantasizing about what you’re like to watch). If you notice such a pattern, try to spice up your delay technique to make it more practical, for example instead of just waiting for 20 minutes, commit to do some activity for 20 minutes, like taking a walk.
SMART Recovery has a spin-off technique called Deny & Delay. Here's how they describe it:
Deny & Delay (Don’t give in to the urge) — Remind yourself, repeatedly if necessary, this urge will pass. Refuse to give into it — no matter what! — SMART Handbook