We have implemented and tested an algorithm for onsite earthquake early warning (EEW) in California using the infrastructure of the Southern California Seismic Network (SCSN). The algorithm relies on two parameters derived from the initial 3 sec of P waveform data at a single seismic sensor: period parameter τc and high-pass filtered displacement amplitude Pd. Previous studies have determined empirical relationships between τc and the moment magnitude Mw of an earthquake, and between Pd and the peak ground velocity (PGV) at the site of observation. In 2007, seven local earthquakes in southern California with 4.0≤ML≤4.7 have triggered the calculation of Mw and PGV by the EEW algorithm. While the mean values of estimated parameters were in the expected range, the scatter was large, in particular for the smallest events. During the same time period the EEW algorithm produced a large number of false triggers due to low trigger thresholds. To improve the real-time performance of the onsite approach, we have developed a new trigger criterion that is based on combinations of observed τc and Pd values. This new criterion removes 97% of previous false triggers and leads to a significant reduction of the scatter in magnitude estimates for small earthquakes.