SOME African migrants forge across the Mediterranean in flimsy boats. Others take a somewhat less risky (and cheaper) journey, heading for the bright lights of South Africa. Unemployment may be a shocking 34% south of the Limpopo river, but there are still plenty of opportunities for those who are prepared to work hard.

Many migrants follow in the footsteps of their compatriots. Malawians and Mozambicans are often found tending lush suburban gardens. Somalis run tiny convenience stores, known as spaza shops, in black townships. Johannesburg’s “Little Addis” bustles with Ethiopian traders and the sound of Amharic. Congolese and Cameroonian vendors hawk cassava and plantains in Yeoville, another Johannesburg neighbourhood. Zimbabweans, who are typically better educated than their South African peers, can be found totting up company accounts, working as mining engineers or, failing that, waiting on tables. For many Africans, South Africa seems a stable, functional, prosperous place. It is also a potential stepping stone to the rest of the world.

Getting there is not easy. Many do it in stages, finding work along the way. Some are arrested and locked up. On South Africa’s border with Zimbabwe migrants must ford crocodile-infested rivers. Happily, the main fence is so tattered that you can simply walk through it. At many posts, border guards demand bribes.

Some of the greatest dangers for migrants arise after they arrive. Last year seven people were reportedly killed in a spate of anti-foreigner violence, though the real number is probably much higher since most attacks never make the news. Thousands of immigrants fled their homes and businesses. Among them was Salat Abdullahi, 20, who moved from Somalia to Soweto to run a spaza shop with his older brother. They ran away when xenophobic locals looted and destroyed it. “We came here with nothing, and made a business,” Mr Abdullahi said. “They don’t like that.”

After the violence against migrants came a crackdown on the victims: more than 15,000 immigrants were arrested and deported in a government sweep. Many were held in a detention centre notorious for overcrowding, corruption and abuse.

Xenophobia has spread since 1994, when the fall of apartheid led to an inflow of black migrants from across the continent. The South African government has discouraged immigration, despite a shortage of home-grown skills, by tightening border controls and laws. It sees foreigners as competing with locals for scarce jobs rather than as boosting the economy with their talent and entrepreneurial nous. Despite a widespread perception among South Africans that their country is packed with immigrants, the latest census found just 2.2m of them, or less than 5% of the population (though people in the country illegally probably don’t confess this to census officers, so the true figure is higher). In Johannesburg, the most cosmopolitan of South African cities, 13% of the population was born abroad.

Many of those who come seek asylum: the South African government lets refugees work and even obtain some public services while their papers are being processed. Between 2008 and 2012 South Africa received 778,000 asylum applications, in a system that is slow and riddled with corruption. Despite the well-documented hostility and harassment, foreigners are still more likely to be employed than South Africans. Often they work in the informal sector, or do jobs that locals are not willing to take. Enterprising migrants rent shops from South Africans and thereby create jobs. Johannesburg, built on gold mines and migrant labour, is becoming a truly international city. But local elections this year could be the catalyst for more foreigner-bashing.