# PHP Backend for Insider Trading Analyzer This directory contains PHP scripts that handle server-side operations for the Insider Trading Analyzer application. ## IMPORTANT: GETTING REAL BSE DATA **The application cannot access real BSE data directly from the browser due to CORS restrictions.** To use real data instead of simulated data, you MUST: 1. Deploy the PHP scripts in this directory to a web server with PHP support 2. Set up the scheduler.php to run at regular intervals (via cron job or similar) 3. Make sure your web server is accessible to the frontend application Without these steps, the application will only show simulated data, not real BSE website data. ## Why Browser-Only Solutions Don't Work - **CORS Restrictions**: Browsers prevent direct API calls to external domains for security reasons - **ScraperAPI Requirements**: ScraperAPI must be called from a server, not directly from a browser - **PHP Execution**: PHP code cannot run in a browser; it must run on a server ## Server Setup Instructions ### Requirements - PHP 7.2 or higher - cURL extension enabled - Web server (Apache, Nginx, etc.) - ScraperAPI account (API key: `167259cf89a5c56e0e7ca670d6534743`) ### Quick Deployment Steps 1. Upload the PHP files to your web server 2. Make sure the directory has write permissions (for logs and data storage) 3. Test the scraper by accessing `http://your-server.com/path/to/scraper.php?url=https://www.bseindia.com/corporates/Insider_Trading_new.aspx` 4. Set up the scheduler to run continuously or at regular intervals ### Cron Job Setup To run the scheduler every 2 minutes: ``` */2 * * * * /usr/bin/php /path/to/scheduler.php >> /path/to/cron.log 2>&1 ``` Alternatively, for continuous operation, use Supervisor: ```ini [program:insider-trading-scheduler] command=/usr/bin/php /path/to/scheduler.php directory=/path/to autostart=true autorestart=true user=www-data redirect_stderr=true stdout_logfile=/path/to/logs/scheduler.log ``` ## Connection Between Frontend and Backend Once your PHP backend is deployed to a server, update the frontend configuration to point to your server: 1. Edit `scraper.js` to update the `phpScraperUrl` to your server's URL 2. Make sure your server has CORS headers enabled to allow requests from your frontend For local testing, you can run a PHP development server: ``` cd /path/to/php/directory php -S localhost:8000 ``` Then update the frontend to use `http://localhost:8000/scraper.php` as the backend URL.