Any recommendations for hosting this kind of script – PHP – SitePoint Forums

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.

while ($play != 'stop'){
// keep running this code

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.

Thanks and happy new year in advance

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.

  1. 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.

  2. 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 think this is the key thing you need to take.

I understand, but when you are holding a hammer, everythhing looks like a nail. :slightly_smiling_face:
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.

  1. 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.

So who is doing the changes in the database?

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

Initially how i designed the workflow is that.

  1. i got a signal from tradingview
  2. adds records to database
  3. post the order and get the orderid as response from binance.
  4. start the loop if orderid is not empty and the loop checks for when order gets filled.
  5. once the orderid gets filled it updates the database and set the status to completed
  6. then the loop exit.

waiting to be started again anytime a signal is sent from tradingview.

This works well except that before the order gets filled or executed it may take minutes or even hours and by then my while loop have timeout

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

What I don’t understand…

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

the status does not come from tradingview, it only comes from binance after you must have placed order.

  1. signal from tradingview asking you to buy at this rate or price.
  2. add the signals details to the database and set the default value to pending.
  3. post the order to binance
  4. start the daemon that will be making an API call to binance to know when the order status changes from NEw Order to FILLED order
  5. update your database and mark the order as completed.
  6. exit the looping.

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.

‘orderid’ => ‘685884678’,
‘symbol’ => ‘BTCUSDT’,

Use the above code to check your order status which returns NEW, FILLED, CANCELLED as order status.

So all am asking or the essence of my question is how to be running this code automatically until the Status is becomes FILLED.

So i was using while loop but it keeps timing out

I don’t think this can be done by a hosting. In this case you would need to rent a server.

This may not be relevant, but I should look at this direction.

Set up VPS that you have root access to. Create a micro process that manage this. Something like this (less than 10 MB without Apache/Nginx). I use Cron to export from database every night to a ftp server.

1 Like

can this be archived updating the page without some one visiting it in a browser?

because the gocron minimum interval is 60secs but am looking at a 5secs interval process

sounds like an expensive approach? can i know the cost let me see if is something i can afford.

Source link


Leave a Reply

Your email address will not be published. Required fields are marked *