Jami` at-Tirmidhi 3564
Ali said:
“I was ill and the Messenger of Allah (ﷺ) passed by me while I was saying: ‘O Allah, if  my term has come, then give me relief, and if it is coming later, then make my life more bountiful, and if it is a trial then make me patient (Allāhumma, in kāna ajalī qad ḥaḍara fa ariḥnī, wa in kāna muta’akh-khiran fa arfighnī, wa in kāna balā’an fa ṣabbirnī).’ So the Messenger of Allah (ﷺ) said: ‘What did you say?’” He said: “So he repeated to him what he said.” He (one of the narrators) said: So he struck him with his foot and said: “O Allah, grant him health (Allāhumma `āfihi)” – or – “heal him (ishfihi).” – Shu`ba is the one who doubted. He said: “So I did not suffer from my ailment again.”
حَدَّثَنَا مُحَمَّدُ بْنُ الْمُثَنَّى، حَدَّثَنَا مُحَمَّدُ بْنُ جَعْفَرٍ، حَدَّثَنَا شُعْبَةُ، عَنْ عَمْرِو بْنِ مُرَّةَ، عَنْ عَبْدِ اللَّهِ بْنِ سَلِمَةَ، عَنْ عَلِيٍّ، قَالَ كُنْتُ شَاكِيًا فَمَرَّ بِي رَسُولُ اللَّهِ صلى الله عليه وسلم وَأَنَا أَقُولُ اللَّهُمَّ إِنْ كَانَ أَجَلِي قَدْ حَضَرَ فَأَرِحْنِي وَإِنْ كَانَ مُتَأَخِّرًا فَأَرْفِغْنِي وَإِنْ كَانَ بَلاَءً فَصَبِّرْنِي ‏.‏ فَقَالَ رَسُولُ اللَّهِ صلى الله عليه وسلم ‏"‏ كَيْفَ قُلْتَ ‏"‏ ‏.‏ قَالَ فَأَعَادَ عَلَيْهِ مَا قَالَ قَالَ فَضَرَبَهُ بِرِجْلِهِ فَقَالَ ‏"‏ اللَّهُمَّ عَافِهِ أَوِ اشْفِهِ ‏"‏ ‏.‏ شُعْبَةُ الشَّاكُّ ‏.‏ فَمَا اشْتَكَيْتُ وَجَعِي بَعْدُ ‏.‏ قَالَ أَبُو عِيسَى وَهَذَا حَدِيثٌ حَسَنٌ صَحِيحٌ ‏.‏