Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

496
Visualizações
python script return null when I execute it with php exec()

Today I have a question for php exec()

I have three files(2 of them are PHP files, the other one is Python). A PHP file(file 1 ) receives an input value and sends it to another PHP file(file2).

file 2 makes a parameter with values it got from file 1. after that It execute python file(file3) with exec() and it also got return data and send it back to file1.

so,

file1 :

  $.ajax({
                    url: "./section_result.php",
                    type: 'post',
                    dataType: 'json',
                    data: { 'search': search, 'target': target, 'keyword' : keyword.val() }
                }).done(function(data){
                    console.log('done...', data)
}

file2:

$search = $_POST['search'];
$target = $_POST['target'];
$keyword = str_replace("\n", ",", trim($_POST['keyword']))
$command = '/home/ubuntu/venv/bin/python /home/ubuntu/pypypython/';

$command = sprintf('%s "%s" "%s"', $command, $keyword, $target);

exec($command, $output);
http_response_code(200);
echo $output[0];

file 3 :

if __name__ == "__main__":
    start_time = time.time()   
    url = sys.argv[1]
    users = [] 
    users = do_something_sympathy(url)    
    driver = get_blog_comment(url)
    something = do_random_info(driver)
    users.extend(do_reply_scrap(driver))
    driver.close()
    driver.quit()
    users = list({user['url']: user for user in users}.values())

    data = { 'title' : blog['title'], 'posted' : blog['posted'], 'social' : users }
    json_data = json.dumps(data, ensure_ascii=False)        
    print(json_data)
    # print(url)
    print("--- Data count : %s" % len(users))
    print("--- elapsed time %s seconds ---" % (time.time() - start_time))

it used to work fine apparently(as far as I heard) but somehow it stops work (return null when I console.log it).

I thought that's due to problem of path or something at the first place. However when I execute python file with FTP environment it worked perfectly fine. (like $ python random_website_comment.py "https://blahblah.com/abadacadabra" "mo")

I was lost but I found a clue after all. my python file has some delay methods such as webdriverWait, sleep et Cetra. and sum of their delay time is over 10seconds. but when I submit input in file 1, it only took a 2 or 3 seconds to get return null.

but what I don't understand is doesn't exec() function wait until it got return data? also my max_execution_time on php.info is 30seconds which is enough to wait til exec() is accomplished.

If you know about how to deal with this issue, please share with me.

thx for reading, your help will be appreciated.

over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda