Well, you could do it one of two ways.
Use a database
You could create a small mysql database just to keep a counter of the number of visitors that have been through your site. Just add a row with dummy data in it (like their IP). You can do a quick count of the rows to see how many have been there and if they would be #4000, then show the prompt.
Text Files
You could use text-files to do the counter as well. Except instead of storing the ips and counting the number of records, you could just keep a number in the file. Increment that number with each visitor. If you wanted to get really intricate, you could impose file locking so that multiple visitors don't see the pop-up.