You can apply for asylum at the border, with an urgent process time of 4 days, typically for arrivals without a valid visa.
Applications within Spain generally take 6 months by law, with some cases expedited to 3 months. In reality, it often takes between 2 to 4 years to receive a resolution.