When to publish a book?
No.  Absolutely not.

Do not even start writing a book until you have tenure, unless publishing a book is a requirement for tenure (which would be very strange for computer science).  Writing books well is extremely hard; it requires significant time away from your research (which you need to finish your PhD, get a job, and get tenure), teaching, paper-writing, professional networking, job-hunting, proposal writing, and advising.  And writing books badly can only hurt you.