Home Apache2, PHP file always running and accessible from any request
Reply: 0

Apache2, PHP file always running and accessible from any request

user46999
1#
user46999 Published in September 19, 2018, 11:01 am

Is there any way to make a php file always running and accessible from others php files/requests?

I want to make a functions, objects, variables or some others things always running on the server.

Example:

[alwaysrunning.php]

$conn = fsockopen($serverip, $serverport, $errno, $errstr, $ex);

[index.php]

fwrite($conn, $command."\n");

Sorry my english and thank you!

share|improve this question
  • Include your functions in a file (somefunctions.php). Then in your index.php file, include them: require_once('...PATH.../somefunctions.php'); Then call the functions required to initiate connections and others. Look at this: stackoverflow.com/questions/4458837/… – Nic3500 Apr 16 at 14:47
  • @Nic3500 i don't want include, i want that variable never die, always running, like in other thread. – xXNurioXx Apr 16 at 14:48
  • 1
    What problem are you actually trying to solve? There's no technical reason this can't be done, but it's definitely not a common pattern. – iainn Apr 16 at 14:53
  • 3
    PHP is inherently stateless, the request starts, the caller receives a response and that's that. If you want to maintain state PHP is not the answer. If you want to have access to it in the current request(something like a global state), that's a different matter. – Andrew Apr 16 at 14:53
  • 1
    Well in that case a different language is not the answer. Even if you kept a persistent connection it's still a connection. And PHP does offer that too pecl_http. If you want to have access to the information in the file on a regular basis nginx is really good at serving static content or just use a CDN and solve the connection to your system all together. – Andrew Apr 16 at 15:15

active oldest votes

Your Answer

StackExchange.ifUsing("editor", function () { StackExchange.using("externalEditor", function () { StackExchange.using("snippets", function () { StackExchange.snippets.init(); }); }); }, "code-snippets"); StackExchange.ready(function() { var channelOptions = { tags: "".split(" "), id: "1" }; initTagRenderer("".split(" "), "".split(" "), channelOptions); StackExchange.using("externalEditor", function() { // Have to fire editor after snippets, if snippets enabled if (StackExchange.settings.snippets.snippetsEnabled) { StackExchange.using("snippets", function() { createEditor(); }); } else { createEditor(); } }); function createEditor() { StackExchange.prepareEditor({ heartbeatType: 'answer', convertImagesToLinks: true, noModals: false, showLowRepImageUploadWarning: true, reputationToPostImages: 10, bindNavPrevention: true, postfix: "", onDemand: true, discardSelector: ".discard-answer" ,immediatelyShowMarkdownHelp:true }); } });
 
StackExchange.ready( function () { StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f49860102%2fapache2-php-file-always-running-and-accessible-from-any-request%23new-answer', 'question_page'); } );

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged php multithreading asynchronous pthreads apache2 or ask your own question.

StackExchange.ready(function(){$.get('/posts/49860102/ivc/5731');});
StackExchange.ready(function () { StackExchange.responsiveness.addSwitcher(); }) (function(i, s, o, g, r, a, m) { i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function() { (i[r].q = i[r].q || []).push(arguments) }, i[r].l = 1 * new Date(); a = s.createElement(o), m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m); })(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga'); StackExchange.ready(function () { StackExchange.ga.init({ sendTitles: true, tracker: window.ga, trackingCodes: [ 'UA-108242619-1' ] }); StackExchange.ga.setDimension('dimension2', '|php|multithreading|asynchronous|pthreads|apache2|'); StackExchange.ga.setDimension('dimension3', 'Questions/Show'); StackExchange.ga.trackPageView(); }); /**/ var _qevents = _qevents || [], _comscore = _comscore || []; (function() { var ssl = 'https:' == document.location.protocol, s = document.getElementsByTagName('script')[0], qc = document.createElement('script'); qc.async = true; qc.src = (ssl ? 'https://secure' : 'http://edge') + '.quantserve.com/quant.js'; s.parentNode.insertBefore(qc, s); _qevents.push({ qacct: "p-c1rF4kxgLUzNc" }); /**/ var sc = document.createElement('script'); sc.async = true; sc.src = (ssl ? 'https://sb' : 'http://b') + '.scorecardresearch.com/beacon.js'; s.parentNode.insertBefore(sc, s); _comscore.push({ c1: "2", c2: "17440561" }); })();
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.415896 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO