here is what I want to do: I want to make an 'executable-like' application running on a web server, with a doSomething() function. On web application startup, the doSomething() function connects as a client to another MQTT server through web sockets, subscribes there, and stores the incoming messages to a database. I don't care about the content of the doSomethihg() function. I can do this. I am only interested in making a deamon app in a web server. This application will run either in glassfish (java) or apache (php). I will deploy this application in openshift o another similar PAAS, so it must be a web app, no a standalone one. Plus, I suppose I don't have the ability to execute shell scripts. I only found a way to do this with java; Make a servlet and configure it to run at application startup (use load-on-startup in web.xml file). I don't know if this is the most efficient, and I didn't find anything for php. Thanks in advance!
1条回答 默认 最新
- duanbanzhi4419 2017-02-07 08:06关注
PHP doesn't have an 'application startup' per se, but it sounds like you may want a cron job. You can create a cron job to run every so many minutes, and it will launch its function without any user interaction. Setting a conditional flag in a cron job would ensure that the code only ever runs once.
Alternatively, you can execute a function whenever a particular page is loaded by a visitor. This function could set a flag (as a
$_SESSION
variable) that checks whether or not the function has already run:<?php session_start(); if(!isset($_SESSION['done'])) { doSomething(); } function doSomething() { // Do something $_SESSION['done'] = 'yes'; } ?>
That way you can get the function to trigger once per visitor if need be.
Hope this helps! :)
解决 无用评论 打赏 举报
悬赏问题
- ¥100 set_link_state
- ¥15 虚幻5 UE美术毛发渲染
- ¥15 CVRP 图论 物流运输优化
- ¥15 Tableau online 嵌入ppt失败
- ¥100 支付宝网页转账系统不识别账号
- ¥15 基于单片机的靶位控制系统
- ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
- ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
- ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
- ¥15 手机接入宽带网线,如何释放宽带全部速度