This is going to sound obvious, but in practice it should work - stay engaged. Have an activity that takes up your mind that you can have access to at basically all times, especially when you are on the computer. Games works for me - it can be on your phone, or you can open up a quick game of chess at chess.com. You don't have to be an expert chess player (I'm not), it's simply a fantastic distraction.
The best possible engagement would be something actually productive. Know what you want to get done each and every day to move yourself towards your goals professionally, physically, and in relationships. Chances are, when you are thinking about loading up some P, there are some of those tasks you haven't accomplished yet.
As men, we have egos. It's part of the deal. It's completely natural for us to ask the world, "What makes me significant?" When the world responds with evidence we are significant, be it with money, or sex with those we are attracted to, we are happy and our emotional needs are met. It's when the evidence isn't there, and we aren't getting an answer to that question that our insecurities are unearthed, and we may turn to other ways to give us that feeling of significance. P can be one of those other ways.
Instead of asking the question, "What makes me significant?" I've been asking the question, "How can I contribute?" This does a couple of things. First, it doesn't even address what I'm getting out of it, so it's not based in ego. Second, it's a positive, the language of that question already assumes that I can do it, it's simply a matter of how. Finally, and this is important, the best way for us to actually feel significant is to be significant, and guess how you become significant? CONTRIBUTE! Show me someone who has made a lot of money (legally) that hasn't made huge contributions through their work. Show me someone who has an amazing relationship with an attractive woman (or man) that doesn't contribute every day to that person's life. Even physically, you re contributing to your future self when you stay away from unhealthy foods and spend time exercising. Those actions do very little for your present self, you are contributing to your future self by doing those.
And guess what the answer NEVER is to the question "How can I contribute?" Pull up some videos and jerk it out. Your mind won't be thinking about it all. Bottom line, by asking yourself this question, you are effectively pulling yourself away from addiction AND you are moving yourself forward in life. Win-win.