It's a bit unclear what you mean by "nation" and "foreign rule," and if your question is "what is the longest" or, is there a place that was under foreign rule longer than the Philippines.
But - we have several places, according to what appear to be your criteria, that were under foreign rule longer than the 333 years you cite for the Philippines, although not all of them as as long as the total for the Philippines if you include also American and Japanese rule:
Goa is a former Portuguese province; the Portuguese overseas
territory of Portuguese India existed for about 450 years until it was
annexed by India in 1961.
Parts of New Guinea, which has a complicated history:
The first European contact with New Guinea was by Portuguese and
Spanish sailors in the 16th century. In 1526-27 the Portuguese
explorer Jorge de Meneses saw the western tip of New Guinea and named
it ilhas dos Papuas. In 1528 Spanish navigator Álvaro de Saavedra also
recorded its sighting when trying to return from Tidore to New Spain.
In 1545 the Spaniard Íñigo Ortíz de Retes sailed along the north coast
of New Guinea as far as the Mamberamo River near which he landed on 20
June, naming the island 'Nueva Guinea'. The first map showing the
whole island (as an island) was published in 1600 and shows it as
'Nova Guinea'. In 1606 Luís Vaz de Torres explored the southern coast
of New Guinea from Milne Bay to the Gulf of Papua including Orangerie
Bay which he named Bahía de San Lorenzo. His expedition also
discovered Basilaki Island naming it Tierra de San Buenaventura, which
he claimed for Spain in July 1606. On October 18 his expedition
reached the western part of the island in present-day Indonesia, and
also claimed the territory for the King of Spain.
Another candidate might be Inner Mongolia:
The eastern Mongol tribes near and in Manchuria, particularly the
Khorchin and Southern Khalkha in today's Inner Mongolia intermarried,
formed alliances with, and fought against the Jurchen tribes until
Nurhaci, the founder of the new Jin Dynasty, consolidated his control
over all groups in the area in 1593...
Indonesia: Following three and a half centuries of Dutch
colonialism, Indonesia secured its independence after World War II.
(Wiki is apparently calculating from 1602 when the Dutch East India Company became the dominant force in Indonesia until 1949, when Indonesia finally achieved complete independence from the Dutch.)
So here you have three or more places which might meet your criteria. But if you look carefully over the map I am certain there are more places, depending on your exact criteria, particularly islands in the Pacific, the Mediterranean and the East and West Indies.
Consider for example Autonomous Region of the Azores (under Portuguese administration)
One (unproven) hypothesis is that the Azores were discovered in the
course of a 1341 mapping expedition to the Canary Islands, sponsored
by King Afonso IV of Portugal and commanded by the Florentine
Angiolino del Tegghia de Corbizzi and the Genoese Nicoloso da
Recco. Although not quite described in the 1341 report, Madeira
and the Azores might nonetheless have been seen from a distance on the
expedition's return via a long sailing arc (volta do mar) from the
Canary islands. Even if not discovered by the 1341 mapping
expedition itself, the islands may have been found by any of the
numerous Majorcan expeditions that were launched into the Atlantic
Ocean in the aftermath, destined for slaving runs on the newly-mapped
Canary islands. Nonetheless, regardless of who sighted them in the
14th century, there seems to have been no follow-up until the 15th century.
Autonomous Region of the Madeira (under Portuguese administration
Madeira was discovered by Portuguese sailors in the service of Infante
D. Henrique (Henry the Navigator) in 1419, and settled after 1420. The
archipelago is considered to be the first territorial discovery of the
exploratory period of the Portuguese Age of Discovery.
Canary Islands - one of Spain's 17 autonomous communities:
There may have been a Portuguese expedition that attempted to colonize
the islands as early as 1336, but there is not enough hard evidence to
support this. In 1402, the Castilian conquest of the islands began,
with the expedition of French explorers Jean de Béthencourt and
Gadifer de la Salle, nobles and vassals of Henry III of Castile, to
Lanzarote. From there, they conquered Fuerteventura (1405) and El
Hierro. Béthencourt received the title King of the Canary Islands, but
still recognized King Henry III as his overlord.
British Virgin Islands are (today still) a British overseas
The Dutch established a permanent settlement on the island of Tortola by 1648. In 1672, the English captured Tortola from the Dutch, and the English annexation of Anegada and Virgin Gorda followed in 1680. Meanwhile, over the period 1672–1733, the Danish gained control of the nearby islands of Saint Thomas, Saint John and Saint Croix.
Depending on how one calculates, the British Virgin Islands might be considered "under foreign rule" for over 350 years.
In medieval and ancient times, we have more examples to consider, for example:
Gaul - today France:
Roman control of Gaul lasted for five centuries, until the last Roman
rump state, the Domain of Soissons, fell to the Franks in AD 486
Roman Britain, referred to by the Romans as Britannia, was the part of
the island of Great Britain controlled by the Roman Empire from 43 AD until c. 410.
Ancient Egypt, under the Greeks and Romans was ruled by these two powers continuously from 323 BC until at least 269 AD, a period of well over 500 years. (However, as Lennart Regebro has pointed out in the comments, it is debatable if the Ptolemaic Kingdom constituted an extension and continuation of the Greek Empire, or it was an Egyptian entity, the result of usurpation of the Egyptian throne by the Greek Ptolemies - see the comments regarding this):
The Ptolemaic Kingdom (/ˌtɒləˈmeɪ.ɪk/; Greek: Πτολεμαϊκὴ βασιλεία,
Ptolemaïkḕ Basileía)1 was a Hellenistic kingdom in Egypt. It was
ruled by the Ptolemaic dynasty that Ptolemy I Soter founded after the
death of Alexander the Great in 323 BC—which ended with the death of
Cleopatra VII and the Roman conquest in 30 BC...
The Roman province of Egypt (Latin: Aegyptus, pronounced
[ai̯ˈgyp.tus]; Greek: Αἴγυπτος Aigyptos [ɛ́ːɣyptos]) was established
in 30 BC after Octavian (the future emperor Augustus) defeated his
rival Mark Antony, deposed his lover Queen Cleopatra VII and annexed
the Ptolemaic kingdom of Egypt to the Roman Empire. The province
encompassed most of modern-day Egypt except for the Sinai Peninsula
(which would later be conquered by Trajan).
Zenobia, queen of Palmyra, took the country away from the Romans when
she conquered Aegyptus in 269, declaring herself the Queen of Egypt
Transylvania (now consolidated into Romania):
Between 1003 and 1526, Transylvania was a voivodeship of the Kingdom
of Hungary, led by a voivode appointed by the Hungarian King.
Perhaps Albania (Investigate also other nations in far eastern Europe who were ruled by the Ottomans for long periods of time - they may also be candidates):
The Ottomans erected their garrisons throughout southern Albania by
1415 and established formal jurisdiction over most of Albania by
1431....Albania remained under Ottoman control as part of the Rumelia province until 1912, when the first independent Albanian state was
Clearly, although the Philippines was indeed under "foreign rule" for a long period of time, it cannot lay claim to the dubious distinction of having the longest such period. Of all the examples cited, IMO Egypt, Gaul, and Transylvania might best qualify as the "longest," all in the neighborhood of 500 years, being quite clearly defined geographic areas with fairly homogeneous, indigenous populations that were conquered and ruled continuously by arguably true nation-states in the modern sense. In the modern era, Goa is probably the best example
But we could go on, depending on your time parameters, and definitions of "nation", and "foreign rule", which is why your question has been closed.