ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Basically I don't think this is possible. PHP is running as a module, however the persistent connection is associated with a specific process. Since Apache is multi-threaded in nature it's very likely that the connection is not available in the process I'm running my script in.
Without completely reconfiguring Apache on my dev server I don't know. Has any one had any experience with this in the past? I've updated my code and I believe everything should be working at this point.
I am also facing the same problem; have you found any possible solution. I don't want to create socket again and again.
You can reply me at my mail mastermailbox2001-manager@yahoo.com
Unfortunately there is no way to maintain the same socket over multiple requests when running in a webserver context. If your application is running from the command line there would be no issue because the script would maintain the socket as long as it is executing, or you specifically kill it.
Unfortunately there is no way to maintain the same socket over multiple requests when running in a webserver context. If your application is running from the command line there would be no issue because the script would maintain the socket as long as it is executing, or you specifically kill it.
Sorry :\
Yes Now I understand, I changed my application to work in that way.
Unfortunately there is no way to maintain the same socket over multiple requests when running in a webserver context. If your application is running from the command line there would be no issue because the script would maintain the socket as long as it is executing, or you specifically kill it.
Sorry :\
This is wrong.
pfsock is a persistant socket the same way pconnect works for a mysql connection.
The dev resource is opened and when ever you call pfsock again it will call the same dev resource until the interpreter runs its gc which only takes things not used after 30 min. So yes it seems that you will be opening a new sock every time, but using pfsock it uses the smae resource when opened.
From PHP.net
"This function behaves exactly as fsockopen() with the difference that the connection is not closed after the script finishes. It is the persistent version of fsockopen()."
This would do the trick at the top of each script or the one opened over and over.
xhypno, have you read the comments on, http://php.net/pfsockopen/. I think you'll find it's a bit more complicated than you assume depending on how PHP is being executed. IE: ISAPI Module, PHP as a CGI, Apache Prefork or Worker MPM, all have different behavior in this regards.
xhypno, have you read the comments on, http://php.net/pfsockopen/. I think you'll find it's a bit more complicated than you assume depending on how PHP is being executed. IE: ISAPI Module, PHP as a CGI, Apache Prefork or Worker MPM, all have different behavior in this regards.
I have actually used it a lot. The only time it will be complicated is with Apache Prefork as each page call is in a new fork of apache and a new php interpreter. But the chances you are doing it in prefork is very slim because you only see that in large scale shared hosting environments that have been poorly designed where each user forks their own apache and php instance each time a page is accessed instead of chrooting them to one environment. You see this in a few of the Affinity/Hostway hosting services but that is about it because it is a very poor practice.
It seems that when running php in almost any fashion on a web server - pfsockopen serves no purpose.
Each time the script is run, a new socket is instantiated.
It's fairly easy to test... run it - and see how many connections you have after a few refreshes.
xhypno - I would love to see an example of how you are running it so the sockets are re-used.
To be honest, I think it would be a bit of a security issue in a webserver environment anyway. How would you identify yourself as the rightful owner of the socket?
I'm not sure how this is a security concern. It's not like someone can take over your socket when it's in use. PHP just doesn't tear down the connection when you're done, so the person obtaining the persistent socket has no idea whether it was persistent or a brand new connection.
thank you nathacof beracuse of your good illustration I have the same code like you with pfsockopen and no problem in apache I mean for each web page or session that opens on different client I have individual persistent socket and it does not close and everything goes fine and every session has its own socket but with on lighthttpd and fastcgi enable, my persistent socket will share for all web pages I mean all of different sessions have just one persistent socket .
as you said :
Quote:
Using FastCGI however, should allow you to share persistent connections across all of your scripts
I do not want fastcgi to share persistent connections across all of my sessions and I want each session has its own persistent socket.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.