DrQuincy Posted December 20, 2021 Share Posted December 20, 2021 My hosting environment does not allow for PHP to run for more than 120 seconds when it is a web request. However, there is no limit via command line PHP. Is it possible take a ProcessWire URL such as http://domain.com/foo/bar/?bar=foo and run it as a PHP command line? Something like: php /path/to/pw/site/index.php route=/foo/bar/ bar=foo Is such a thing possible? Thanks. Link to comment Share on other sites More sharing options...
bernhard Posted December 20, 2021 Share Posted December 20, 2021 You can bootstrap PW and create your own command line scripts that have full access to the PW API: https://processwire.com/docs/front-end/include/ 2 Link to comment Share on other sites More sharing options...
DrQuincy Posted December 20, 2021 Author Share Posted December 20, 2021 Thanks, I've seen that. I just wondered if there was a way to — rather then get a page through the API which I could do per your link — get PW to actually process it as though it were a front-end request. If I do wire('page')->get(123) it will retrieve all the data but what I want is to trigger something that is the same as accessing the page through HTTP. Is there a built-in function for this? Link to comment Share on other sites More sharing options...
bernhard Posted December 20, 2021 Share Posted December 20, 2021 Sure, you can access it via WireHttp, but then your 120s limit will apply because it will be seen as a regular web request... $http = new WireHttp(); $http->get("https://your.site/your/url"); 2 Link to comment Share on other sites More sharing options...
DrQuincy Posted December 20, 2021 Author Share Posted December 20, 2021 Ah, yes, thanks for that. I'll have a think about how to implement it. Link to comment Share on other sites More sharing options...
horst Posted December 20, 2021 Share Posted December 20, 2021 @DrQuincy what is this page doing that takes a lot of time? If there is a loop operation that iterates over a lot of items, and you are able to implement an optional get param with the last processed item identifier, there is a good chance that this is all you need to do to make this work. For this to work you would check if a start-identifier was given with the URL, if not start with the first item, otherwise with the #n item from the $input->get->myidentifiername. When starting the script, store a timestamp and in each loop operation compare it with the current timestamp. Maybe when it reached the point greater or equal 100 seconds, do a redirect call to the same page, but with the current (last) processed loop item identifier: ... if(time() >= $starttimestamp + 100) { $session->redirect($page->url . '?itemidentifiername=' . $lastProcessedItemID); } ... Or, much easier, have you tested if the 120 second time limit can be reset from within a script? (calling set_time_limit(120) from within a loop can make it run endless on some server configurations) 4 Link to comment Share on other sites More sharing options...
DrQuincy Posted December 20, 2021 Author Share Posted December 20, 2021 Thanks for your suggestion! In this case it's for something that runs on cron in the night and syncs a website property listing with third-party listing software. It takes a long time to run as it needs to copy images over HTTP and then resize some of them so when the website is accessed during the day it's a lot faster. Thanks for your suggestion though. I must admit I have never thought of doing it that way — it's a neat solution. If you run curl and then redirect via a session as you have done, does curl honour the redirect? I can't say I've never tried that but from when I have used curl in the command line I'm sure it just returns redirect headers, location, etc. I just thought maybe there was a way with the API and get a page's rendered HTML as opposed to as an object to force ProcessWire to run the task as it would if you visited it via a browser. I don't know, I thought maybe there'd be something like $pages->get('/path/to/page/')->render() that returns the page HTML. If so, from my command line script I could simply map the arguments to $_GET and also pass a path. 1 Link to comment Share on other sites More sharing options...
Jan Romero Posted December 20, 2021 Share Posted December 20, 2021 1 hour ago, DrQuincy said: does curl honour the redirect? Only if you tell it to: https://curl.se/docs/manpage.html#-L You’ll also have to increase the maximum number: https://curl.se/docs/manpage.html#--max-redirs 2 Link to comment Share on other sites More sharing options...
DrQuincy Posted December 21, 2021 Author Share Posted December 21, 2021 Thanks Jan! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now