Philip Viljoen joined the Boer forces under General Jan Kemp at the age of twelve to participate in the Anglo-Boer War (1899-1902). After the war he attended the South African College School in Cape Town, where he became the first pupil to win a study bursary from the Transvaal government in 1906. Through the mediation of General Louis Botha he was able to attend the Royal Veterinary College in London, where he qualified (MRCVS) in 1912. He was a keen sportsman and played rugby for both his college and for Old Charltonians, Kent.
Upon his return to South Africa Viljoen was appointed in January 1913 as Veterinary Research Officer (bacteriology) at Onderstepoort. During World War I (1914-1918) he saw service in the South West Africa Campaign, where he was wounded, and awarded the military cross. After the war he was stationed at the Armoedsvlakte research station near Vryburg and the Onderstepoort Veterinary Research Institute. His main contribution during this period was the elucidation, with Arnold Theiler*, of the etiology of lamsiekte, but later he also published on black quarter (1926, with J.R. Scheuber*), parathyroid in calves (1926, 1928, with G. Martinaglia*), anthrax (1928, with H.H. Curson* and P.J.J. Fourie*), and East Coast fever, all of which were diseases of great economical importance to the livestock industry at the time.
In 1919 Viljoen was appointed professor of veterinary science at the Transvaal University College and played an active role in the establishment of the Veterinary Faculty at Onderstepoort. The next year he was promoted to deputy director, Veterinary Services, and in September that year left for further studies in Berne, Switzerland. There he gained the Dr Med Vet degree at the end of 1921 with a thesis entitled Das Vorkommen von Sacrosporidien in Südafrikanischen Tieren (Haustieren und Wild). He became chief of Veterinary Field Services in 1926, and deputy director at Onderstepoort the next year. In 1926 he contributed two papers to the South African Journal of Science: "The occurrence of Paratyphoid, Bacillus enteritidis, infection in calves in South Africa" (with G. Martinaglia*) and "A preliminary communication regarding anthrax spore vaccine and its use in South Africa" (with H.H. Curson*). The next year he published Anthrax; its nature and control (Pretoria, 1927).
In January 1931 Viljoen was appointed under-secretary for the Department of Agriculture, and in May 1933 secretary for the Department of Agriculture and Forestry. It was largely owing to his efforts that the Veterinary Act (No. 16 of 1933) was promulgated, giving statutory recognition to the veterinary profession. He served on various commissions and in several official positions, represented South Africa at various overseas conferences, and ended his public service career with an appointment as High Commissioner in Canada (1945) and Australia (1949). He returned to South Africa at the end of 1951 for health reasons.
Viljoen was a person of exceptional intellectual talents and a great capacity for work. He joined the Transvaal Veterinary Medical Association in 1913 and in 1920 served on the first council of the South African Veterinary Medical Association. Later he was elected honorary vice-president of this association, and also served in the South African Forestry Association, and the National Veld Trust.