In terms of speed, probabaly - but ultimately it depends on message volumes, really.
Security - do you mean it's a dedicated server, or a shared server? A dedicated server is always better, because there's a risk that if it's a shared server, other people may be able to see something in the logs, or access a database table that you've not properly secured. So, make sure you have the permissions for the table set as strictly as possible. Make sure your PHP script is written defensively, so that people can't feed it invalid information to get someone else's data in or out of the database - for example, that might mean that when the app requests a message from the server, you check not just the message id, but also that the recipient matches whatever id the app is using to retrieve the message, and so on.
Secure the web server using certificates (for example, from LetsEncrypt, if you're just experimenting) so that data is encrypted to and from the server.
If you want to go further, either your app or the server side scripts could encrypt the messages before storing them in the database, using recipients' public keys.
In terms of doing this all in real time, that's what my website and the associated apps do. When a user starts our Android app, it signs into the website and receives a session token to identify the user. It also registers with GCM (now, I'd use Firebase, but I've not yet updated that side of things), and when it has an ID for that, it passes it on to the server, and we store the GCM id in a database
When someone, either on the website, or via the app, creates a new message to a member:
1. The message is inserted into the database table
2. We check to see if there's a valid session for that user, and if so, if there's is a GCM id associated with it
3. If the GCM id is found, then we send a notification via GCM/Firebase, which says 'New message on BLUF' with the payload indicating the sender, and a short extract of the message (up to 250 chars), and the message id
4. The notification arrives in the app via GCM, and the app requests the full message from the server
5. The server uses the session token to verify that the message requested is for the user, and if so returns the full message to the app
Most of the time, the GCM notifications will arrive within a second of the message originally being sent. This is plenty fast enough to appear to be a real time chat, though obviously as you get more users, you'll have to scale up your systems accordingly.
In terms of sending, the app posts a message to a script on the server, which includes the destination member id, the session token, and the text of the message