Hello everyone please i need a recommendations for a good hosting company where i can host a simple script.
The code in the script is an infinity loops and i expect the loop to run for more than 6 or more hours before termination. but if it can run forever until i manually terminate it i will be glad.
set_time_limit(0);
while ($play != 'stop'){
// keep running this code
sleep(5);
}
my hosting company terminates after 3minutes and i get 500 server error request timeout.
even when i have set_time_limit(0);
on the script and the maximum execution time on my server is 1500
Yet it jeeps timing out, also i have contacted the hosting company and they have not responded positively on the cause, they said they are still checking. please I need a recommendations and if you run similar codes in your hosting without it timing out please let me know.
I guess no hosting company will allow you to do this. It will generate high cpu usage without any need. Tell us what you want to achieve in a whole. I will bet there is a way to not need to run a script infinitely every 5ms.
really, i was having that same fear too.
okay the simple thing i tried to do is to check binance orders until they get filled or executed.
$sendorder = binance_check_order(): // this returns a set of ids
While($sendorder != 'FILLED'){
// Keep checking
}
it works in a simple php, and i know php a bit better than other languages, but the issue is the timeout.
Also not that don’t need to manually trigger this looping, the loop gets triggered from a signal sent from tradingview, so everything is automatic flow.
So is not something i can start with a command line or CLI.
unless i can actually start a CLI with php if statement.
from most research i discovered an infinity loops is a very bad idea.
I have to accomplish my aim using this two methods that comes to my mind even when i don’t know how to implement them.
create a php file to be doing the checking, then using ajax script or JavaScript to be calling or posting data to the script using setInterval ()
so once the php file receives a post data it will run the checks. so this happens every 5secs and it means my JavaScript needs to be run or hosted in a nodejs environment or any environment that will run JavaScript remotely.
start a php daemon to be checking this functions every 5secs but then and set a time to know if the daemon is running.
All of the two mentioned methods am very clueless about how to implement them, their sever implications and their security loop holes or exposures
I understand, but when you are holding a hammer, everythhing looks like a nail.
If we know exactly what your aim is, someone can probably point you to the right tools for the job.
PHP is designed to execute a script, complete the execution and deliver its result at the end. It is not supposed to run continuously. You can have cron jobs that run periodically, but I’m not sure how efficient that is at a high frequency.
I’m sure there will be some other method more suitable for your needs.
cron jobs is really out of the picture, I have explained what i intend to archive and i have also stated two options in my mind.
am thinking of a CLI approach.
Since an infinity loops in php running as a script is a bad idea.
I am thinking this steps.
manually start a php daemon to be checking a database every 5secs and once its sees a record in the database whose status is pending, it takes the orderid from the orderid column and call a script named check.php
So anytime check.php returns a response FILLED it call another script named update.php which will update the table and sent status to close where id is orderid.
Then loop keeps checking the database again looking for a row where status is pending.
Something like that indefinitely.
I think am using a complex analysis, let me simplify it. i want to be checking me database every 5secs to know when the word BREAD is found in the database so i can delete.
so i created a file called delete.php
and inside the file it has this code
$sql = $con->query("delete from table where box = 'BREAD'");
Normally i could make this script running indefinitely by adding
while (true){
$sql = $con->query("delete from table where box = 'BREAD'");
}
made from the signals or response from tradingview.
once i got a signal from tradingview it adds details to the database and set the status to pending, then the infinity loops takes the orderid and start checking on binance to know when the order is FILLED and once filled it updates the database with the status completed
if i want to accomplish this workflow using CLI it won’t be possible except i have to start an indefinite loop that never stops. then inside the daemon i will be doing different tasks inside the loop.
Alternatively, if there is a way to start a CLI or daemon once it get to stage 4 instead using while loop as a script functions i will start a CLI automatically.
Let me even check how to start a CLI to run a daemon and see if it last longer than 2hours compared to while loop called directly as a script web server function
You get a signal from the trading view if something changes and you put the order to the database. So why do you not get a signal from the trading view when the order changes its status? This would be the correct way to handle that
This sounds for me as if you are do some kind of screen grabbing on Binance? Binance has an API. I don’t wantmto read the whole documentation but I guess this would be the correct way to use?
What is screen grabbing? i don’t know what that is, binance provided API to check your order status which you need the orderid or clientOrderId to access.
you use this api call fapi/v1/order
with some parameters to post your order to binance.