From Liquipedia Starcraft Wiki
The Photon Cannon is a highly versatile defensive building capable of attacking both air and ground with a ranged attack (range=7). It is extremely useful in every Protoss match-up as many builds, particularly the Fast Expansion against Zerg, rely on them. They require no Psi and can be built quickly. They are also detectors for the Protoss, often used to repel Dark Templar and Lurkers.
Photon Cannons are frequently spread out to maximize the number of hits dealt to non-ranged units. Photon Cannons can be used to secure the middle and divide players, on maps such as The Hunters when playing 3v3 or 4v4. In 2v2, when Terran bio sees more usage, one may opt to make Photon Cannons above his own ramp to repel Marines and Firebats. Also, in 2v2, it is viable to contain a Terran enemy with Photon Cannons if he has teched Bio and not Metal.
In Korea, Photon Cannons are sometimes referred to as "Flowers" due to their shape. Large groups are therefore dubbed "Flower Fields" and a particular player may be dubbed "Flowertoss" for prolific use of "Flowers."
Photon Cannons are of great importance for a Protoss player against a Zerg player in the early-game and mid-game. Photon Cannons behind walls do quite well against frontal attacks, and Photon Cannons are regularly built along any mineral lines to protect workers from potential Mutalisk Harassment or if a Dark Templar drop is anticipated.
In team games, a Protoss might make a Photon Cannon to break a Terran's wall off and allow allies or his own Zealots to come into the enemy's base. Also, Photon Cannons are often made in team games above your ramp if you need to hold off large amounts of enemy units. They are especially effective here against non-ranged melee units such as Zerglings, Zealots, or Firebats. In team games, sometimes a Protoss player can help his ally out by making him cannons above his ally's ramp.
A player can Photon Cannon rush an enemy. The best way to this is to make the first building or buildings slightly out of range of the enemy being targeted. However, you should not attempt to do this against a Terran because he will float to his expansion and rebuild. Furthermore, when attempted to break the Photon Cannon push, you should attack the Photon Cannons from the angle where you will be attacked back the least.
 Related Articles