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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.