0

I have created a site in laravel.

Where i use below code to get result from an external python script.

$ssh = new \phpseclib\Net\SSH2("11.111.11.11", 22);
ignore_user_abort(true);
set_time_limit(0);
$ssh->setTimeout(0);
$result = $ssh->exec("python /url_to_remote_python_file $site $keywords ", $output, $ret_code);

If i get an array back that takes arround 3 minutes to complete everything works fine.

I just found out that the problem is that the php call is hanging for a very long time, when the python script has finished its not sending anything back so the php call just hangs, how can that be?

But when i request a larger array from my python script i get a timeout with below code.

502 bad gateway nginx 1.8.0

I tried to follow the link Prevent nginx 504 Gateway timeout using PHP set_time_limit() but i am still getting 502 bad gateway when calling exsternal python script, can the exsternal server be the problem?

I whould like to make it work manualy before making it run as a cron job, whould that at all be possible.?

I have tried to put the script in laravel queue system. But there it only works if the script runs for about 3 minutes. If the script runs for, lets say 10 minutes the queue listener and log doesn't return anything back to me.

How can i call a python script from php and make sure i get a result back.

I need to run my script every night at around twelve a clock to populate my database when new results, but i need to make it work manualy first.

What is the best way to make this happen?

11
  • 1
    Possible duplicate of Prevent nginx 504 Gateway timeout using PHP set_time_limit() Commented Jul 12, 2016 at 11:51
  • I will take a look at the link @KikiTheOne do u have any good idea to how i can make the script run each night at arround 12 a clock? Commented Jul 12, 2016 at 11:56
  • as @Bruno already said. u can use a cronjob to do so. if u dont want to use a cronjob u can use Ajax->php if u adjust the timeout. and while running u set the database with a flag so no user can write stuff or Change stuff till the Ajax->php is rdy. this way u can do this stuff the first time a user calls ur site after 12 o clock. Commented Jul 12, 2016 at 12:04
  • Thanks @KikiTheOne im gonna look into php-cli and see if i should set it up as a cronjob, if i whould like to manualy click a button and start the script call, then i need to change my php.ini settings timeout correct? Is there no timeout when i do it from crom? Commented Jul 12, 2016 at 12:19
  • there still is a timeout. cause ur Server gets no Response from ur Server. :) Commented Jul 12, 2016 at 13:43

1 Answer 1

0

Your problem is with your web server. If your script is supposed to run as a cron job, you don't need a web server, so just write it as a command-line script (using php-cli).

Sign up to request clarification or add additional context in comments.

2 Comments

In the end i would like to run it as a cron job, but right now i want to run it manually so i can ensure it works as expected. Is that at all possible?
If you can't run it "manually" (from the command line that is) you can't run it as cron job obviously...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.