Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

498
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda