On Unix systems, there is no such thing as a shared library that keeps active in memory, even when the programs that use it have all stopped. If this is indeed what you're looking for, you will have to develop a specific server application that runs "forever", and to which client programs can connect and send instructions.
The communication between the client and server normally happens over a network connection, and not within the same process. You could use shared memory if setting up a network connection is indeed a no-go. It reduces the amount of data that has to be copied between the client and server process - but it is a solution that you do not see very often. Network communication (or local sockets) are very common to communicate between client and servers.
Very popular applications to store data are of course databases. If the main goal of your forever-running "shared library" would be to centralize a sort of cache, you could just as well use a database.
With SWIG you indeed have the option to program in C and export the C functions to PHP. But you're right, such a solution is not persistent. Every time that the PHP engine starts, your shared library is re-initialized too. And if multiple instances of the PHP engine are started, multiple instances of your shared library are started too - each with their own data space (although with shared memory you can ensure that all these instances have access to the same data).
An alternative for SWIG would be the PHP-CPP library. This library also allows you to build PHP extensions using C++, and has more expression power than SWIG. But the same limitations apply here: it is not persistent.
By the way, once a PHP extension is loaded, it will be used to serve hundreds or even thousands of pageviews before the extension is unloaded. This means that you can optimize your extension to keep certain data in memory. Not forever - but at least for a long time.